Jump to content

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


bobleny

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";

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.