Re: amazing syntax error
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: amazing syntax error

From: Hilarion <hilarion@SPAM.op.SMIECI.pl>
Date: Wed Dec 28 2005 - 17:02:08 CET

Dean <qsvqs@qsdcsqd> wrote:

> Amazing. Maybe more a PHP problem.
>
> This little phscript works perfect with PHP 5.0 and Mysql 5.0 ...under
> Windows with IE and Netscape 8.0. Exactly the
> same script gives a syntax error on line: b=<?=$rec?> (little green arrow
> pointing to <?) with PHP 5.0 and Mysql 5.0
> and Netscape 7.2 under Linux (redhat 9.0).
>
> The script code:
> <html><body>
> <?php
> $link = mysql_connect("localhost", "root", "pw")
> or die("Impossible de se connecter : " . mysql_error());
> $dbsel = mysql_select_db('mydb', $link);
> $sql = "SELECT logon, number FROM mytable";
> $result = mysql_query($sql);
> $rec=mysql_num_rows($result);
> echo $rec; // = 12
> ?>
>
> <script type="text/javascript">
> b = <?=$rec?>; // error line
> alert(b);
> </script>
>
> </body></html>
>
> (Variable $rec = 12 )
>
> I really don't know what's wrong with this code ...
> Do you?
> Thanks
> Dean

The error is not related to PHP version, MySQL version, your OS or
(PHP errors never are) to the browser. The problem is probably
related to your PHP settings. In the first case (when the script
works) you have short tags turned on, and in the second case
you have short tag turned off.
Read about "short_open_tag" setting in "php.ini" (or --enable-short-tags
configuration directive).

In general usage of short tags is discouraged because it makes
your script less portable (it will not work with short tags turned
off).

Change this:

b = <?=$rec?>;

to this:

b = <?php echo $rec; ?>

and the script will work regardless of short tags being on or off.
(Also do not use "<?" instead of "<?php" - it's also a short tag,
not only "<?=").

Hilarion
Received on Tue Jan 3 03:47:39 2006