Bluehost.com Web Hosting $6.95

syntax error

This is a discussion on syntax error within the PHP General forums, part of the PHP Programming Forums category; On a system with php4 and mysql 4.x I had these lines: require("../db-config"); // includes $dbhost, $...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-21-2008
Ronald Wiplinger
 
Posts: n/a
Default syntax error

On a system with php4 and mysql 4.x I had these lines:

require("../db-config"); // includes $dbhost, $buname, $dbpass
$db = mysql_connect($dbhost, $dbuname, $dbpass);
mysql_select_db($dbname,$db);

$sql = "SELECT * FROM CATEGORY WHERE .....";
$result = mysql_query($sql,$db);
$num=mysql_num_rows($result);
while ($myrow = mysql_fetch_array($result)) {
.....

Moving the *.php to a php5 and mysql 5.x site I get these errors:

PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL
result resource in ...
PHP Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in ...


Looking at the manual, I cannot see what I am doing wrong.

bye

R.

Reply With Quote
  #2 (permalink)  
Old 07-21-2008
Ted Wood
 
Posts: n/a
Default Re: [PHP] syntax error


Not a syntax error. It's not successfully connecting to the database.
Check your settings.

~Ted



On 21-Jul-08, at 4:24 AM, Ronald Wiplinger wrote:

> On a system with php4 and mysql 4.x I had these lines:
>
> require("../db-config"); // includes $dbhost, $buname, $dbpass
> $db = mysql_connect($dbhost, $dbuname, $dbpass);
> mysql_select_db($dbname,$db);
>
> $sql = "SELECT * FROM CATEGORY WHERE .....";
> $result = mysql_query($sql,$db);
> $num=mysql_num_rows($result);
> while ($myrow = mysql_fetch_array($result)) {
> ....
>
> Moving the *.php to a php5 and mysql 5.x site I get these errors:
>
> PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL
> result resource in ...
> PHP Warning: mysql_fetch_array(): supplied argument is not a valid
> MySQL
> result resource in ...
>
>
> Looking at the manual, I cannot see what I am doing wrong.
>
> bye
>
> R.


Reply With Quote
  #3 (permalink)  
Old 07-21-2008
Eric Butera
 
Posts: n/a
Default Re: [PHP] syntax error

On Mon, Jul 21, 2008 at 7:24 AM, Ronald Wiplinger <tm.ronald@gmail.com> wrote:
> On a system with php4 and mysql 4.x I had these lines:
>
> require("../db-config"); // includes $dbhost, $buname, $dbpass
> $db = mysql_connect($dbhost, $dbuname, $dbpass);
> mysql_select_db($dbname,$db);
>
> $sql = "SELECT * FROM CATEGORY WHERE .....";
> $result = mysql_query($sql,$db);
> $num=mysql_num_rows($result);
> while ($myrow = mysql_fetch_array($result)) {
> ....
>
> Moving the *.php to a php5 and mysql 5.x site I get these errors:
>
> PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL
> result resource in ...
> PHP Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
> result resource in ...
>
>
> Looking at the manual, I cannot see what I am doing wrong.
>
> bye
>
> R.
>


Your mysql_connect is probably failing. Look at your error log or
look at mysql_error() for a reason why.
Reply With Quote
  #4 (permalink)  
Old 07-21-2008
Aschwin Wesselius
 
Posts: n/a
Default Re: [PHP] syntax error

Eric Butera wrote:
> On Mon, Jul 21, 2008 at 7:24 AM, Ronald Wiplinger <tm.ronald@gmail.com> wrote:
>
>> On a system with php4 and mysql 4.x I had these lines:
>>
>> require("../db-config"); // includes $dbhost, $buname, $dbpass
>> $db = mysql_connect($dbhost, $dbuname, $dbpass);
>> mysql_select_db($dbname,$db);
>>
>> $sql = "SELECT * FROM CATEGORY WHERE .....";
>> $result = mysql_query($sql,$db);
>> $num=mysql_num_rows($result);
>> while ($myrow = mysql_fetch_array($result)) {
>> ....
>>
>> Moving the *.php to a php5 and mysql 5.x site I get these errors:
>>
>> PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL
>> result resource in ...
>> PHP Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
>> result resource in ...
>>
>>
>> Looking at the manual, I cannot see what I am doing wrong.
>>
>> bye
>>
>> R.
>>
>>

>
> Your mysql_connect is probably failing. Look at your error log or
> look at mysql_error() for a reason why.


Probably the mysql extension is not found or not loaded (due to not
being compiled with the right path or the default path in PHP is not the
right one). Happened to me a couple of times.....


--

Aschwin Wesselius

/'What you would like to be done to you, do that to the other....'/

Reply With Quote
  #5 (permalink)  
Old 07-21-2008
Eric Butera
 
Posts: n/a
Default Re: [PHP] syntax error

On Mon, Jul 21, 2008 at 7:55 AM, Aschwin Wesselius
<aschwin@illuminated.nl> wrote:
> Eric Butera wrote:
>
> On Mon, Jul 21, 2008 at 7:24 AM, Ronald Wiplinger <tm.ronald@gmail.com>
> wrote:
>
>
> On a system with php4 and mysql 4.x I had these lines:
>
> require("../db-config"); // includes $dbhost, $buname, $dbpass
> $db = mysql_connect($dbhost, $dbuname, $dbpass);
> mysql_select_db($dbname,$db);
>
> $sql = "SELECT * FROM CATEGORY WHERE .....";
> $result = mysql_query($sql,$db);
> $num=mysql_num_rows($result);
> while ($myrow = mysql_fetch_array($result)) {
> ....
>
> Moving the *.php to a php5 and mysql 5.x site I get these errors:
>
> PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL
> result resource in ...
> PHP Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
> result resource in ...
>
>
> Looking at the manual, I cannot see what I am doing wrong.
>
> bye
>
> R.
>
>
>
> Your mysql_connect is probably failing. Look at your error log or
> look at mysql_error() for a reason why.
>
> Probably the mysql extension is not found or not loaded (due to not being
> compiled with the right path or the default path in PHP is not the right
> one). Happened to me a couple of times.....
>
>
> --
>
> Aschwin Wesselius
>
> 'What you would like to be done to you, do that to the other....'
>


Wouldn't that be call to undefined function then?
Reply With Quote
  #6 (permalink)  
Old 07-21-2008
Aschwin Wesselius
 
Posts: n/a
Default Re: [PHP] syntax error

Eric Butera wrote:
> On Mon, Jul 21, 2008 at 7:55 AM, Aschwin Wesselius
> <aschwin@illuminated.nl> wrote:
>
>> Probably the mysql extension is not found or not loaded (due to not being
>> compiled with the right path or the default path in PHP is not the right
>> one). Happened to me a couple of times.....
>>
>>
>> --
>>
>> Aschwin Wesselius
>>
>> 'What you would like to be done to you, do that to the other....'
>>
>>

>
> Wouldn't that be call to undefined function then?


Oh my..... I'm so sorry. You're absolutely right. I mixed these two. I'm
a bit side-tracked today.....

Thanks for pointing that out.


--

Aschwin Wesselius

/'What you would like to be done to you, do that to the other....'/

Reply With Quote
  #7 (permalink)  
Old 07-21-2008
Eric Butera
 
Posts: n/a
Default Re: [PHP] syntax error

On Mon, Jul 21, 2008 at 8:32 AM, Aschwin Wesselius
<aschwin@illuminated.nl> wrote:
> Oh my..... I'm so sorry. You're absolutely right. I mixed these two. I'm a
> bit side-tracked today.....
>
> Thanks for pointing that out.
>
>
> --
>
> Aschwin Wesselius



It's no problem, I got scared I was spreading propaganda! hehe :)
Reply With Quote
  #8 (permalink)  
Old 07-21-2008
Daniel Brown
 
Posts: n/a
Default Re: [PHP] syntax error

On Mon, Jul 21, 2008 at 7:24 AM, Ronald Wiplinger <tm.ronald@gmail.com> wrote:

Try this:

> $result = mysql_query($sql,$db) or die(mysql_error());


--
</Daniel P. Brown>
Better prices on dedicated servers:
Intel 2.4GHz/60GB/512MB/2TB $49.99/mo.
Intel 3.06GHz/80GB/1GB/2TB $59.99/mo.
Dedicated servers, VPS, and hosting from $2.50/mo.
Reply With Quote
  #9 (permalink)  
Old 07-21-2008
Daniel Brown
 
Posts: n/a
Default Re: [PHP] syntax error

Please keep replies on list for all to benefit and be able to assist.

On Mon, Jul 21, 2008 at 5:47 PM, Ronald Wiplinger <tm.ronald@gmail.com> wrote:
>
> On Tue, Jul 22, 2008 at 1:51 AM, Daniel Brown <parasane@gmail.com> wrote:
>>
>> Try this:
>>
>> > $result = mysql_query($sql,$db) or die(mysql_error());


Did you try my suggestion above? If so, did you receive any errors?

> echo "result=$result<br>";
> $num=mysql_num_rows($result);
> echo "num=$num";
>
> I get:
>
> result=
> num=


The most you'd get from $result in this case would be a resource
identifier message, because that's all mysql_query() returns. And
since the resource link doesn't seem to be correctly established, $num
will be empty.

--
</Daniel P. Brown>
Better prices on dedicated servers:
Intel 2.4GHz/60GB/512MB/2TB $49.99/mo.
Intel 3.06GHz/80GB/1GB/2TB $59.99/mo.
Dedicated servers, VPS, and hosting from $2.50/mo.
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 02:42 AM.


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