Jump to content

[SOLVED] echo "hello" . echo $text; . "good bye"; - ?????


Recommended Posts

I have this line:

echo "<input type='text' name='first' size='10' value='".if(isset($_POST['change'])==TRUE){echo $_POST['first'];}else{echo 'john';}."' />\r\n";

 

As expected, that doesn't work:

Parse error: syntax error, unexpected T_IF in /home/bob/Web Devolpment/Server/Auburn/index.php on line 277

 

I am trying to change the value of the input field based on $_POST['change'].

Link to comment
https://forums.phpfreaks.com/topic/46652-solved-echo-hello-echo-text-good-bye/
Share on other sites

you can't use the if statement withing the echo statement, break it down like this

echo "<input type='text' name='first' size='10' value='";

if(isset($_POST['change'])==TRUE){
echo $_POST['first'];
}
else{
echo 'john';
}

echo "' />\r\n";

$myChange = (isset($_POST['change']))?$_POST['first']:'john';
echo "<input type='text' name='first' size='10' value='".$myChange."' />\r\n";

 

You cannot really have an if statement inside the echo, this might also work (note untested)

 

echo "<input type='text' name='first' size='10' value='", (isset($_POST['change']))?$_POST['first']:'john', "' />\r\n";

 

That and if something is suppose to be true, you do not need to ==, just simply doing it like I have above works.

echo "<input type='text' name='first' size='10' value='". (isset($_POST['change'])==TRUE) ? echo $_POST['first'] : echo 'john' />rn";

 

Should be...

 

echo "<input type='text' name='first' size='10' value='" . isset($_POST['change']) ? $_POST['first'] : 'john' ."'/>\r\n";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.