amazing syntax error

This is a discussion on amazing syntax error within the PHP Language forums, part of the PHP Programming Forums category; Amazing. Maybe more a PHP problem. This little phscript works perfect with PHP 5.0 and Mysql 5.0 ...under ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-28-2005
Dean
 
Posts: n/a
Default amazing syntax error

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


Reply With Quote
  #2 (permalink)  
Old 12-28-2005
Ewoud Dronkert
 
Posts: n/a
Default Re: amazing syntax error

Dean wrote:
> <script type="text/javascript">
> b = <?=$rec?>; // error line
> I really don't know what's wrong with this code ...


http://php.net/ini.core#ini.short-open-tag

--
E. Dronkert
Reply With Quote
  #3 (permalink)  
Old 12-28-2005
Oli Filth
 
Posts: n/a
Default Re: amazing syntax error

Dean said the following on 28/12/2005 15:50:
> 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 ...


Well, you haven't said whether you're getting a PHP syntax error or a
JavaScript error. If it's JavaScript error, then the PHP has nothing to
do with it, and vice versa. Either way, it's nothing to do with MySQL
(this is evident from the fact that echo $rec; gives a value).

In future, please learn to narrow down the possible causes, and post to
appropriate groups accordingly, as well as snipping irrelevant bits of code.


Note that whether you're able to use <?= ?> tags is
configuration-dependent, namely "short tags" option. Look it up in the
manual...

--
Oli
Reply With Quote
  #4 (permalink)  
Old 12-28-2005
Hilarion
 
Posts: n/a
Default Re: amazing syntax error

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
Reply With Quote
  #5 (permalink)  
Old 12-28-2005
Dean
 
Posts: n/a
Default Re: amazing syntax error

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



Reply With Quote
  #6 (permalink)  
Old 10-09-2007
Good Man
 
Posts: n/a
Default Re: amazing syntax error

"Gregory Nickoloff" <greg@nickoloff.org> wrote in
news:LPOdnWtP4_36KJbanZ2dnUVZ_sLinZ2d@buckeye-express.com:

> Are you saying it runs correctly on one server configuration but not
> the other, or that the different configurations you mention are
> different client setups being served?


that was an "amazing" thread pickup! last previous response, December
2005!!!

Reply With Quote
  #7 (permalink)  
Old 10-10-2007
John Hosking
 
Posts: n/a
Default Re: amazing syntax error

Good Man wrote:
> "Gregory Nickoloff" <greg@nickoloff.org> wrote in
> news:LPOdnWtP4_36KJbanZ2dnUVZ_sLinZ2d@buckeye-express.com:
>
>> Are you saying it runs correctly on one server configuration but not
>> the other, or that the different configurations you mention are
>> different client setups being served?

>
> that was an "amazing" thread pickup! last previous response, December
> 2005!!!


He's improving; over in a.w.webmaster he's been responding to posts from
May of this year. If he keeps this up, in a week he'll be replying to
threads from 1997.

:-P

--
John
Reply With Quote
  #8 (permalink)  
Old 10-16-2007
David McKenzie
 
Posts: n/a
Default Re: amazing syntax error

John Hosking wrote:
> Good Man wrote:
>> "Gregory Nickoloff" <greg@nickoloff.org> wrote in
>> news:LPOdnWtP4_36KJbanZ2dnUVZ_sLinZ2d@buckeye-express.com:
>>> Are you saying it runs correctly on one server configuration but not
>>> the other, or that the different configurations you mention are
>>> different client setups being served?

>>
>> that was an "amazing" thread pickup! last previous response, December
>> 2005!!!

>
> He's improving; over in a.w.webmaster he's been responding to posts from
> May of this year. If he keeps this up, in a week he'll be replying to
> threads from 1997.
>
> :-P
>

Re: WorldWideWeb: Summary
Dear Tim Berners-Lee,

Thanks for telling us about the WorldWideWeb, any idea when this will be
implemented?

Thanks,
Gregory Nickoloff

--
DM davidm@cia.com.au

'It would go against respecting principles and truth if you have to
respect and accept anything just because it is the other side's view.'
- Kim Jung Ill
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:57 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0