Answer the question
In order to leave comments, you need to log in
Sessions in PHP, what's the problem?
I don't know how to elaborate my question, but I'll try.
I want to make it so that in the form input field (input value) the information entered by the user after updating the page is saved and displayed, for this I used the following code
<input type="text" name="username" value="<?=$_SESSION['reg']['username'];?>"/><br />
<input type="text" name="name" value="<?=$_SESSION['reg']['name'];?>"/><br />
etc. Answer the question
In order to leave comments, you need to log in
Bad but working option:
<input type="text" name="username" value="<[email protected]$_SESSION['reg']['username'];?>"/><br />
<input type="text" name="name" value="<[email protected]$_SESSION['reg']['name'];?>"/><br />
$username = '';
if (isset($_SESSION['reg']['username'])) {
$username = $_SESSION['reg']['username'];
}
turn off the display of NOTIS in the production version and there will be no problems.
In short - a call to an unknown variable, you need to initialize before you output.
you can check - if there is $_SESSION['reg']['username'] - output it, otherwise empty
did you try to initialize it on the server before showing the form and fill it with empty lines?)
Use this
Source function here: stackoverflow.com/questions/9555758/php-default-ar...
function get(&$var, $default=null) {
return isset($var) ? $var : $default;
}
$test = array('foo'=>'bar');
get($test['foo'],'nope'); // bar
get($test['baz'],'nope'); // nope
get($test['spam']['eggs'],'nope'); // nope
get($undefined,'nope'); // nope
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question