newbie mysql and php

This is a discussion on newbie mysql and php within the PHP General forums, part of the PHP Programming Forums category; hello I'm new with php just learning and i have just a problem with the following code $dbconnect = mysql_connect(&...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-28-2003
Tony
 
Posts: n/a
Default newbie mysql and php

hello

I'm new with php just learning and i have just a problem with the following
code

$dbconnect = mysql_connect("localhost", "prog_tony","PASSWORD");
mysql_select_db("prog_dealer", $dbconnect);
$stop = 0;
$counter = 1;
while(!$stop){
$query = "SELECT name FROM category WHERE id = $counter";
$dbdo = mysql_query($query,$dbconnect);
while($row= mysql_fetch_array($dbdo)){
if($row[0]){
$counter++;
}else{
$stop=1;
}
$row[0] = "";
}

}



I'm getting an error with mysql_fetch_array() which is line 14 because I
didn't show the other lines since it is not relevant.
here is the error
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
resource in /home/prog/public_html/php/cateadded.php on line 14

Thank you
Reply With Quote
  #2 (permalink)  
Old 12-28-2003
Chris
 
Posts: n/a
Default RE: [PHP] newbie mysql and php

It looks like mysql_query is failing, add these two lines to your code, and
see what message pops up:

...
$dbdo = mysql_query($query,$dbconnect);
if(false === $dbdo) echo mysql_errno(),': ',mysql_error();
else echo 'The query worked, $dbdo value is:',$dbdo;
while($row= mysql_fetch_array($dbdo)){
...


Chris

-----Original Message-----
From: tony [mailto:awardd@essex.ac.uk]
Sent: Saturday, December 27, 2003 4:18 PM
To: php-general@lists.php.net
Subject: [php] newbie mysql and php


hello

I'm new with php just learning and i have just a problem with the following
code

$dbconnect = mysql_connect("localhost", "prog_tony","PASSWORD");
mysql_select_db("prog_dealer", $dbconnect);
$stop = 0;
$counter = 1;
while(!$stop){
$query = "SELECT name FROM category WHERE id = $counter";
$dbdo = mysql_query($query,$dbconnect);
while($row= mysql_fetch_array($dbdo)){
if($row[0]){
$counter++;
}else{
$stop=1;
}
$row[0] = "";
}

}



I'm getting an error with mysql_fetch_array() which is line 14 because I
didn't show the other lines since it is not relevant.
here is the error
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
resource in /home/prog/public_html/php/cateadded.php on line 14

Thank you

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Reply With Quote
  #3 (permalink)  
Old 12-28-2003
Tony
 
Posts: n/a
Default Re: [PHP] newbie mysql and php

the problem i get is that its say no database selected

Anthony


"Chris" <chris@leftbrained.org> wrote in message
news:JCEBKEIIBIOHLMACLNFDIEECCKAA.chris@leftbraine d.org...
> It looks like mysql_query is failing, add these two lines to your code,

and
> see what message pops up:
>
> ...
> $dbdo = mysql_query($query,$dbconnect);
> if(false === $dbdo) echo mysql_errno(),': ',mysql_error();
> else echo 'The query worked, $dbdo value is:',$dbdo;
> while($row= mysql_fetch_array($dbdo)){
> ...
>
>
> Chris
>
> -----Original Message-----
> From: tony [mailto:awardd@essex.ac.uk]
> Sent: Saturday, December 27, 2003 4:18 PM
> To: php-general@lists.php.net
> Subject: [php] newbie mysql and php
>
>
> hello
>
> I'm new with php just learning and i have just a problem with the

following
> code
>
> $dbconnect = mysql_connect("localhost", "prog_tony","PASSWORD");
> mysql_select_db("prog_dealer", $dbconnect);
> $stop = 0;
> $counter = 1;
> while(!$stop){
> $query = "SELECT name FROM category WHERE id = $counter";
> $dbdo = mysql_query($query,$dbconnect);
> while($row= mysql_fetch_array($dbdo)){
> if($row[0]){
> $counter++;
> }else{
> $stop=1;
> }
> $row[0] = "";
> }
>
> }
>
>
>
> I'm getting an error with mysql_fetch_array() which is line 14 because I
> didn't show the other lines since it is not relevant.
> here is the error
> Warning: mysql_fetch_array(): supplied argument is not a valid MySQL

result
> resource in /home/prog/public_html/php/cateadded.php on line 14
>
> Thank you
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

Reply With Quote
  #4 (permalink)  
Old 12-28-2003
Tony
 
Posts: n/a
Default Re: newbie mysql and php

Hi,

I fixed it, I have not realize that my database was not connected to a user.

so when i logged as prog_tony dealer was not a member of prog_tony so it
could not be found.

thanks for the help

"Tony" <awardd@essex.ac.uk> wrote in message
news:20031227231753.14198.qmail@pb1.pair.com...
> hello
>
> I'm new with php just learning and i have just a problem with the

following
> code
>
> $dbconnect = mysql_connect("localhost", "prog_tony","PASSWORD");
> mysql_select_db("prog_dealer", $dbconnect);
> $stop = 0;
> $counter = 1;
> while(!$stop){
> $query = "SELECT name FROM category WHERE id = $counter";
> $dbdo = mysql_query($query,$dbconnect);
> while($row= mysql_fetch_array($dbdo)){
> if($row[0]){
> $counter++;
> }else{
> $stop=1;
> }
> $row[0] = "";
> }
>
> }
>
>
>
> I'm getting an error with mysql_fetch_array() which is line 14 because I
> didn't show the other lines since it is not relevant.
> here is the error
> Warning: mysql_fetch_array(): supplied argument is not a valid MySQL

result
> resource in /home/prog/public_html/php/cateadded.php on line 14
>
> Thank you

Reply With Quote
  #5 (permalink)  
Old 12-29-2003
Calico Jack
 
Posts: n/a
Default Re: newbie mysql and php

Tony wrote:
> hello
>
> I'm new with php just learning and i have just a problem with the following
> code
>
> $dbconnect = mysql_connect("localhost", "prog_tony","PASSWORD");
> mysql_select_db("prog_dealer", $dbconnect);
> $stop = 0;
> $counter = 1;
> while(!$stop){
> $query = "SELECT name FROM category WHERE id = $counter";
> $dbdo = mysql_query($query,$dbconnect);
> while($row= mysql_fetch_array($dbdo)){
> if($row[0]){
> $counter++;
> }else{
> $stop=1;
> }
> $row[0] = "";
> }
>
> }
>
>
>
> I'm getting an error with mysql_fetch_array() which is line 14 because I
> didn't show the other lines since it is not relevant.
> here is the error
> Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
> resource in /home/prog/public_html/php/cateadded.php on line 14
>
> Thank you

Try checking if the db returned anything before you fetch it.


$dbconnect = mysql_connect("localhost", "prog_tony","PASSWORD");
mysql_select_db("prog_dealer", $dbconnect);
$stop = 0;
$counter = 1;
while(!$stop){
$query = "SELECT name FROM category WHERE id = $counter";
$dbdo = mysql_query($query,$dbconnect);
############ Added this line ###########
if (mysql_num_rows($dbdo) > 0) {
########################################
while($row= mysql_fetch_array($dbdo)){
if($row[0]){
$counter++;
}else{
$stop=1;
}
$row[0] = "";
}
}
}

Reply With Quote
Reply


Thread Tools
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

vB 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 09:53 AM.


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