bobleny Posted April 11, 2007 Share Posted April 11, 2007 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']. Quote Link to comment https://forums.phpfreaks.com/topic/46652-solved-echo-hello-echo-text-good-bye/ Share on other sites More sharing options...
trq Posted April 11, 2007 Share Posted April 11, 2007 <?php echo "<input type='text' name='first' size='10' value='"; if (isset($_POST['change'])) { echo $_POST['first']; } else { echo 'john'; } echo "' />\r\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/46652-solved-echo-hello-echo-text-good-bye/#findComment-227232 Share on other sites More sharing options...
MadTechie Posted April 11, 2007 Share Posted April 11, 2007 try <?php if(isset($_POST['change'])==TRUE) { $X= $_POST['first']; }else{ $X= 'john'; } echo "<input type='text' name='first' size='10' value='".$X."' />\r\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/46652-solved-echo-hello-echo-text-good-bye/#findComment-227234 Share on other sites More sharing options...
nogray Posted April 11, 2007 Share Posted April 11, 2007 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"; Quote Link to comment https://forums.phpfreaks.com/topic/46652-solved-echo-hello-echo-text-good-bye/#findComment-227235 Share on other sites More sharing options...
per1os Posted April 11, 2007 Share Posted April 11, 2007 $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. Quote Link to comment https://forums.phpfreaks.com/topic/46652-solved-echo-hello-echo-text-good-bye/#findComment-227236 Share on other sites More sharing options...
trq Posted April 11, 2007 Share Posted April 11, 2007 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"; Quote Link to comment https://forums.phpfreaks.com/topic/46652-solved-echo-hello-echo-text-good-bye/#findComment-227238 Share on other sites More sharing options...
bobleny Posted April 11, 2007 Author Share Posted April 11, 2007 OK. I'm just going to use a variable and change the variable out side of the echo statement. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/46652-solved-echo-hello-echo-text-good-bye/#findComment-227242 Share on other sites More sharing options...
Barand Posted April 11, 2007 Share Posted April 11, 2007 or you can use the "?" ternary operator <?php echo "<input type='text' name='first' size='10' value='" . (isset($_POST['change']) ? $_POST['first'] : 'john') ."' />\r\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/46652-solved-echo-hello-echo-text-good-bye/#findComment-227244 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.