Hello, can somebody tell me why I get a parse error in this file?
The error message is on line 20 according to the error log, the last line.

<?php // errormsg.php

function error($msg) {
    ?>
    <html>
    <head>
    <script language="JavaScript">
    <!--
        alert("<?=$msg?>");
        history.back();
    //-->
    </script>
    </head>
    <body>
    </body>
    </html>
    <?
    exit;
}
?>

Could it be something to do with the Javascript?

thanks

Recommended Answers

All 7 Replies

By using exit at the last line you missing the closing brace "{" for the function.
But what exactly you want to achieve with this, remember php is server side and the javascript is client side.

remove the comment(//) in the html comment closing section in lineno 11.

I tried removing // but I still have the same problem. I'm trying to get it so I can do this sort of thing:

if (!mysql_query($sql))  
       error('A database error occurred in processing your submission');

you can store that mysql error in some php variable and then display it somewhere else in the script, instead of trying to alert the same thing.
or else simply call the js function to do the same.

The problem seems to happen in any function I have which contains html, even this

function error($msg) {
?>
<html>
<b>hello</b>
</html>
 <?

}
?>

Am I doing something wrong?

on line 17 of your original post, change:

<?

to:

<?php

Alternatively, you can enable short tags in your php.ini file. You will need to change:
short_open_tag = Off

to:
short_open_tag = On

Thanks, that was the problem

on line 17 of your original post, change:

<?

to:

<?php

Alternatively, you can enable short tags in your php.ini file. You will need to change:
short_open_tag = Off

to:
short_open_tag = On

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.