|
Posted by Dean on 12/28/05 18:09
Thanks for your friendly explanation.
"Hilarion" <hilarion@SPAM.op.SMIECI.pl> schreef in bericht
news:douctm$6um$1@news.onet.pl...
> 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
[Back to original message]
|