SearchSearch   

amazing syntax error

 
   Webmaster Forums (Home) -> PHP RSS
Next:  Want to get(retain) Last visited page  
Author Message
Dean

External


Since: Dec 28, 2005
Posts: 6



(Msg. 1) Posted: Wed Dec 28, 2005 4:50 pm
Post subject: amazing syntax error
Archived from groups: alt>comp>databases>mysql, others (more info?)

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
Back to top
Oli Filth

External


Since: Feb 24, 2005
Posts: 842



(Msg. 2) Posted: Wed Dec 28, 2005 4:50 pm
Post subject: Re: amazing syntax error
Archived from groups: per prev. post (more info?)

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
Back to top
Ewoud Dronkert

External


Since: Oct 18, 2005
Posts: 236



(Msg. 3) Posted: Wed Dec 28, 2005 5:01 pm
Post subject: Re: amazing syntax error
Archived from groups: comp>lang>php (more info?)

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
Back to top
Hilarion

External


Since: Aug 23, 2005
Posts: 467



(Msg. 4) Posted: Wed Dec 28, 2005 5:02 pm
Post subject: Re: amazing syntax error
Archived from groups: alt>comp>databases>mysql, others (more info?)

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 top
Dean

External


Since: Dec 28, 2005
Posts: 6



(Msg. 5) Posted: Wed Dec 28, 2005 5:09 pm
Post subject: Re: amazing syntax error
Archived from groups: per prev. post (more info?)

Thanks for your friendly explanation.


"Hilarion" <hilarion RemoveThis @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 top
Gregory Nickoloff

External


Since: Sep 29, 2006
Posts: 5



(Msg. 6) Posted: Tue Oct 09, 2007 5:09 pm
Post subject: Re: amazing syntax error
Imported from groups: comp>lang>php, others (more info?)

This message is not archived
Back to top
Good Man

External


Since: Mar 03, 2006
Posts: 543



(Msg. 7) Posted: Tue Oct 09, 2007 5:09 pm
Post subject: Re: amazing syntax error
Archived from groups: per prev. post (more info?)

"Gregory Nickoloff" <greg DeleteThis @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!!!
Back to top
John Hosking

External


Since: Jan 07, 2007
Posts: 318



(Msg. 8) Posted: Wed Oct 10, 2007 10:54 am
Post subject: Re: amazing syntax error
Archived from groups: per prev. post (more info?)

Good Man wrote:
> "Gregory Nickoloff" <greg RemoveThis @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.

Razz

--
John
Back to top
David McKenzie

External


Since: Jul 18, 2007
Posts: 16



(Msg. 9) Posted: Tue Oct 16, 2007 3:07 am
Post subject: Re: amazing syntax error
Archived from groups: per prev. post (more info?)

John Hosking wrote:
> Good Man wrote:
>> "Gregory Nickoloff" <greg DeleteThis @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.
>
> Razz
>
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 DeleteThis @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
Back to top
Display posts from previous:   
       Webmaster Forums (Home) -> PHP
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum