0

Hi,
I am facing the parser error in the following line:

<td><select name="type"><option value=" ">select the type</option><option value="C" [B]"'.if(trim($_POST['ctype2'])=="C") echo "selected".'"[/B]>Calcium</option><option value="V">Vitamin</option></td>
 </tr>

Error:
Parse error: syntax error, unexpected T_IF in C:\xampp\htdocs\test.php on line 78

5
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by bijoy340
0

Are you concatenating the string ?

I'm not sure what's before of the string you posted above. If you've already used echo for the above line, echo "selected" was the problem. You cannot use echo within echo function. Try with below:

if(trim($_POST['ctype2'])=="C") "selected='selected'"
0

1. Open FTP, locate custom_functions.php, revert to backup.

1. FTP to /custom/custom_functions.php. Upload your backup PHP file.

And you made a horse-sized PHP syntax error. Or your cats had a tussle on the desk. The green BASB save button called you by name… and you panicked. Your server choked because you went cheap on hosting. Goodness knows what you did.

But hitting the save button created a white screen for philosophers to ponder, or perhaps a PHP parse error such as this one:

Don’t bother yourself hitting the back button. It will tempt you, but it won’t work. You have killed your site, your WordPress admin no longer likes you, and you want to cry. This is where you will also realize you never made that backup of custom_functions.php — oh you meant well enough, but you never did. Curses.

Edited by Nick Evan: removed plug

0

You can also do it by using ternary operator.

<? 
echo '<td>
echo <select name="type"><option value=" ">select the type</option><option value="C" "'.((trim($_POST['ctype2'])=="C")?('selected'):('')).'">Calcium</option><option value="V">Vitamin</option></td>
 </tr>';
?>
0

<?
echo '<td>
echo <select name="type"><option value=" ">select the type</option><option value="C" "'.((trim($_POST)=="C")?('selected'):('')).'">Calcium</option><option value="V">Vitamin</option></td>
</tr>';

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.