0

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

4
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by akkkk
0

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.

0

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

Edited by jino: updating

0

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');
0

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.

0

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?

Edited by akkkk: n/a

0

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

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.