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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
"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!!! |
|
|||
|
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 |
|
|||
|
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 |