I have a weird issue where I am trying to use PHP in shorthand to output a value saved in the session. (Basically, if you type in a username and email address when signing up, but you get the email address wrong, instead of it clearing the username field it should persist and then you only have to recorrect the incorrect details.)
This is what I have for the output:
value="<?=$usern_value;?>"
Which is in my input:
<input type="text" id="inputUser" name="username" placeholder="Username" value="<?=$usern_value;?>" />
But it outputs this instead:
This is where the value of $usern_value
is created:
<?php
if(isset($_SESSION['status']['register']['username'])){
$usern_value = $_SESSION['status']['register']['username'];
} else {
$usern_value = "";
}
?>
Try like this
value="<?php echo $usern_value;?>"
Because may be shorthand is not enabled in your php version.I so you need to enable the short_open_tag option in the configuration file php.ini
.You can try one of the following
short_open_tag = On
in your php.ini (the recommended way);ini_set("short_open_tag", 1);
in your code;add the following line to your .htaccess file:
php_value short_open_tag 1
It's not recommend you use short tags (<? ?>). You should use the full length tags (<?php ?>). The short syntax is deprecated, and if you want to make your application portable, it's possible that short open tags are not allowed on another server and hence your application will break.
short_open_tags
are not enabled by default in most recent versions of PHP.
Either edit your php.ini
or try
ini_set('short_open_tag', true);
Generally, and because of the fact that it's not enabled on many servers, for compatibility reason, .... long sentence, simply don't use this kind of syntax.
Depending on the version of php you are using you have to set short_open_tag = 1
in php.ini to get <?=
to work:
From http://ir1.php.net/ini.core:
short_open_tag boolean
...
Note:
This directive also affected the shorthand <?= before PHP 5.4.0, which is identical to <? echo. Use of this shortcut required short_open_tag to be on. Since PHP 5.4.0, <?= is always available.
Simply way change your code like this
<input type="text" id="inputUser" name="username" placeholder="Username" value="<?php echo $usern_value; ?>" />