amazing syntax error

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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:
$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);
echo $rec;  // = 12

<script type="text/javascript">
b = <?=$rec?>;   // error line


(Variable $rec = 12 )

I really don't know what's wrong with this code ...
Do you?

Re: amazing syntax error

Dean wrote:
Quoted text here. Click to load it

E. Dronkert

Re: amazing syntax error

Dean said the following on 28/12/2005 15:50:
Quoted text here. Click to load it

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  


Re: amazing syntax error

Quoted text here. Click to load it

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

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 "<?=").


Re: amazing syntax error

Thanks for your friendly explanation.

Quoted text here. Click to load it

Re: amazing syntax error

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?

Re: amazing syntax error

Quoted text here. Click to load it

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

Re: amazing syntax error

Good Man wrote:
Quoted text here. Click to load it

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.



Re: amazing syntax error

John Hosking wrote:
Quoted text here. Click to load it
Re: WorldWideWeb: Summary
Dear Tim Berners-Lee,

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

Gregory Nickoloff


'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

Site Timeline