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

Recommended Answers

All 4 Replies

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

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.

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>';
?>

<?
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>';

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.