syntax error: how to mix script code with php code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
php12342005
Forum Commoner
Posts: 79
Joined: Mon Mar 21, 2005 3:35 am

syntax error: how to mix script code with php code

Post 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
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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>';
?>
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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>';
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

And don't forget to add "\n" to the end of each echo ;)
Post Reply