1

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:

enter image description here

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 = "";
   }
?>
Francesca
  • 26,842
  • 28
  • 90
  • 153

5 Answers5

5

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

  • set the directive short_open_tag = On in your php.ini (the recommended way);
  • call 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.

Conspicuous Compiler
  • 6,403
  • 1
  • 40
  • 52
웃웃웃웃웃
  • 11,829
  • 15
  • 59
  • 91
2
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.

Daniel W.
  • 31,164
  • 13
  • 93
  • 151
1

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.

Daniel Gimenez
  • 18,530
  • 3
  • 50
  • 70
0

try

value="<? echo $usern_value; ?>"

and make sure you have enabled php to use shorthand. See here

Community
  • 1
  • 1
iamsleepy
  • 550
  • 3
  • 7
0

Simply way change your code like this

<input type="text" id="inputUser" name="username" placeholder="Username" value="<?php echo $usern_value; ?>" />