Display text based on SESSION in PHP [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have the following line of code that displays a user's first name once logged in. I had text that says Welcome, before the echo statement but it looks silly unless you are logged in. Is there a quick way to only display Welcome, if the session FirstName is not empty?
<h2><?php echo "".$_SESSION['FirstName'];?></h2>
I'd like to use PHP isset but I still don't know how to hide Welcome, and display only if the session contains data.

Best way to check the variable or array value exist or not, you can use isset. For ypur case, you can do as follow.
<h2><?php echo ( isset($_SESSION['FirstName'])?"Welcome":"");?></h2>

Related

Replace PHP with text [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have some PHP that displays the users session name in the HTML and if the user is not logged in, then I would like it to display "User" instead.
Can I have an if statement in this case? I tried it myself but I got header errors.
This is what I've tried so far but each practical attempt just spits out more errors at me.
This is a different approach I have tried.
<?=$_SESSION['sess_user'] or ("User");?>!
<?php echo (isset($_SESSION['sess_user']) ? $_SESSION['sess_user'] : "User"); ?>
This will check if the session is set, if it is then echo the session, if it isn't then it will echo "User".

How do I check for a mysql database change without refresh? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to be able to have my main page (index.php) check every 10 seconds for a change in the mysql database table 'refresh'. If the 'refresh' value is 1 it needs to refresh the page in its entirety. If the value is zero it does nothing. I would use meta-refresh but I cannot have the page always refreshing as the page has a slider and it would mess up the rotation. Please let me know what you think of! Thanks in advance!
Use AJAX to check if an update is required.
http://api.jquery.com/jQuery.ajax/
You should learn the basic how to's of AJAX before using something like jQuery when you don't even know what's going on.

How to create a URL where the query parameters are saved to some form of DB [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am looking to create a simple url where I can add URL querys to it and then have these saved to a database.
This would be the format that i'm looking for
example.com?name=value1&email=value2
Could anybody help ?
Get the values on the script from $_GET, then put them in your database using PDO or MySQLi. I don't know your database structure so I can't really help any further:
// In index.php
echo $_GET["name"];
echo $_GET["email"];
// Put them in your database

counting the number of times a script is executed [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have got two php forms - question.php and marks.php. I want that each time question.php submits its values to marks.php , the variable $total in the form marks.php be incremented. I have tried using static variable but still am not able to get it done!
Nothing "inside PHP" itself will persist anything across different page loads. You need to store the value somewhere "external", e.g.:
write it to a file
write it to a database
store it in a memcache or other kind of cache
send it to yourself in an email
burn it into the screen of the computer and use an elaborate video camera and OCR setup to read it back
...
maybe: sessions

How to know if an variable exist in url even thou it dont have any value in php [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Previously I used to add an value like ?help=1 to make PHP know that variable help is used and now it has to show help page. But on a few sites, I have seen they simply use only variables and do not assigned any value (i.e just ?help). Can you please tell me how to do it?
What's wrong with isset($_GET["help"])?
Use PHP's isset function:
if(isset($_GET['help']))
{
echo $_GET['help'];
}
else
{
echo "help is not set";
}
This just means the variable 'help' exists, but has no value. If you maybe left a field blank on a form, it may do this simply so the next script can acknowledge it has no value rather than ignored. It works exactly the same way.

Categories