Page 1 of 1

syntax error: how to mix script code with php code

Posted: Tue Jul 26, 2005 8:42 am
by php12342005
following code has runtime errors,
"hid" is a hidden in a form

//code
$strWho=$_POST['hid'];//php, error also?
print('<script language="javascript">
alert("It is read"+$strWho);
</script>');

note on line 3: "It is read"+$strWho

what is correct code for above purpose?

thanks

Posted: Tue Jul 26, 2005 8:48 am
by hawleyjr
Please read Posting Code in the Forums

viewtopic.php?t=21171

Your quotes are messed up:

Code: Select all

//code
<?php
$strWho=$_POST['hid'];//php, error also?
echo '<script language="javascript">';
echo 'alert("It is read ' . $strWho . '");';
echo '</script>';
?>

Posted: Tue Jul 26, 2005 9:59 am
by timvw

Code: Select all

if (isset($_POST['hid']))
{
  $who = $_POST['hid'];
}
else
{
  $who = 'Hey, nothing is posted!';
}

echo '<script language="javascript">';
echo 'alert("It is read ' . $who . '");';
echo '</script>';

Posted: Tue Jul 26, 2005 10:24 am
by Chris Corbyn
And don't forget to add "\n" to the end of each echo ;)