Page 1 of 1

php & javascript

Posted: Wed Jan 21, 2004 1:32 pm
by tushar
hi friends,
Its me again, I just wanted to know how can write a javascript code in a php.
i have written complete php but wheni write the following lines i get error
following is the code
<?
if(0!=strcmp( $eml, $sr_rec[EML]) )
{
?>
<html>
<SCRIPT LANGUAGE="JavaScript">
function UpdtEID() {
$myact_EMLquery="UPDATE my_act set EML='".$eml."' where SRN='".$sr_no."'";
mysql_query($myact_EMLquery) or die (mysql_error());
$EMLrec_no=mysql_affected_rows();
if( $EMLrec_no!=1)
{
header("Location: error.php?error=10");
exit();
}
// alert("Hello, have a nice day!");
}
</SCRIPT>
<FORM>
<br>
<font face="Arial" size="4" color="black">
<b>
Update Email-ID
</b> <br>
<INPUT TYPE="BUTTON" VALUE="Update Email-ID " onClick="UpdtEID()">
</FORM>
</html>
<? }
echo "The renewal details has been sent to the registered email address.<br>
Please check your mails.<br>
Thank you.";

?>
i get on last line as parse error $ found. if not written in this format <?script ?>
and if i directly write the
Script language = ...
then i am getting Parse error '<' on the line where The <Script Lan...> is written.
How Do i go @ it ???
It really troubling me alot.
ANy help any suggetion welcome
TAHNX in Advance

Posted: Wed Jan 21, 2004 2:36 pm
by pickle
You're really mixing up Javascript and PHP here. UpdtEID has a bunch of PHP code, but it's not in between <?php ?> tags. Therefore it's just being output as text, which is being interpreted as a Javascript function, which, of course, is breaking. If you're trying to get Javascript to call a PHP function, your out of luck. The closest you can get is either get PHP to generate a Javacript function of similar functionality at load time, or use Javascript to load another page, which by being accessed, runs some PHP code.