Why the code can work but still have error message ???

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

acswilson
New php-forum User
New php-forum User
Posts: 18
Joined: Thu Jul 17, 2003 7:42 am

Why the code can work but still have error message ???

Postby acswilson » Sat Sep 06, 2003 2:43 am

Why the code can work but still have error message ???

Warning: Supplied argument is not a valid MySQL result resource in
c:\phpweb/view_group.php on line 41

Code: Select all

34<?
35     echo "<TABLE width=\"40%\" CELLSPACING=\"0\" CELLPADDING=\"0\" BORDER=\"1\" align=center>";
36   echo "<TR><TD width=\"15%\" align=center height=\"30\"><font face=\"Arial Narrow\"><font size=\"4\">Group</font></TD><TD width=\"15%\" align=center height=\"30\"><font face=\"Arial Narrow\"><font size=\"4\">Username</font></TD><td width=\"5%\" align=center><font face=\"Arial Narrow\"><font size=\"4\">Action</td></TR>\n";   
37   while ($number_of_array = mysql_fetch_array($result1))
38   {
39      $call = $number_of_array[group1];
40      $result2 = mysql_query("select * from $call");
41      while ($number_of_array1 = mysql_fetch_array($result2))
42      {
43         echo "<tr>\n";
44         echo "<TD align=center><font face=\"Arial Narrow\"><font size=\"3\">$number_of_array[group1]</font></TD>\n";
45         echo "<TD align=center><font face=\"Arial Narrow\"><font size=\"3\">$number_of_array1[username]</font></TD>\n";
46         echo "<td align=center><font face=\"Arial Narrow\"><form name=\"form1\" method=\"post\" action=\"main3.php?username=$number_of_array1[username]&group2=$number_of_array1[group2]\" onClick=\"return confirm('Are you sure you want to delete this record?  ');\"><br><input type=\"submit\" name=\"Submit\" value=\"Delete\" ></form></font></TD>\n";            
47      }
48   }
49?>

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Sat Sep 06, 2003 9:14 am

i dont see here any SQL....

Joel
New php-forum User
New php-forum User
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand
Contact:

Postby Joel » Sat Sep 06, 2003 4:37 pm

Code: Select all

while ($number_of_array1 = mysql_fetch_array($result2))


When you get this error it means that $result2 didn't return a valid resource - Which could mean it returned nothing. To get around it you could have a conditional like this.

Code: Select all

if (mysql_num_rows($result2) > 0) {
          //while loop
}

User avatar
Redcircle
Moderator
Moderator
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Postby Redcircle » Sat Sep 06, 2003 8:57 pm

39 $call = $number_of_array[group1];
40 $result2 = mysql_query("select * from $call");


if for any reason $call does not have a value it would cause for a misformed sql statement.

i.e.

if $call is null it will try and send
("select * from")

I would put a check to make sure $call has a value before issuing the sql statement.

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Sun Sep 07, 2003 12:42 am

o now i see sql =)

more truly
$query=mysql_query("select * from `". $call ."`");

acswilson
New php-forum User
New php-forum User
Posts: 18
Joined: Thu Jul 17, 2003 7:42 am

Still cannot

Postby acswilson » Wed Sep 10, 2003 8:52 am

Still cannot by using the code that you give me.


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron