#1 (permalink)  
Old 04-29-2008, 06:56 PM
Registered User
 
Join Date: Jul 2004
Posts: 249
warning on myqsl_fetch_array

When I conduct a query within a query I get the following warning on myqsl_fetch_array.

I make my first search into one db table. Then taking the result I search the 2nd table, as you see 2 added next to the 2nd search on $con2, $sql2...

Quote:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in ....php on line 36
PHP Code:
<?php
$bookTitle 
"";
//echo "<span style='font-weight: bold; font-family: Verdana, Times New Roman, serif; font-size: 24px;'>".$bookTitle."</span><br /><br />\n";
$con mysql_connect("","root","");
if (!
$con)
  {
  die(
'Could not connect: ' mysql_error());
  }
mysql_select_db("boti_book"$con);
$i $_GET['page_num'];
//$keyword = "membership lists";
$sql "SELECT * FROM boti_css WHERE fontweight LIKE '%bold%'";
$result mysql_query($sql);
//echo $sql;
while($row mysql_fetch_array($result))
{
    echo 
"<span";
    echo 
" style='font-weight: bold;' ";
    echo 
"><a href='index.php?page_num=".$row['page_num']."' style='text-decoration: none; color: black;'";
?>
onMouseOver='this.style.color="red"; this.style.textDecoration="underline";' onMouseOut='this.style.color="black"; this.style.textDecoration="none";'
<?php    
    
echo ">";
    
$searchPage $row['page_num'].
    
$con2 mysql_connect("","root","");
    if (!
$con2)
      {
      die(
'Could not connect: ' mysql_error());
      }
    
mysql_select_db("boti_book"$con2);
    
$i $_GET['page_num'];
    
//$keyword = "membership lists";
    
$sql2 "SELECT * FROM boti_pages WHERE page_num = ".$searchPage;
    
$result2 mysql_query($sql2);// or die(mysql_error());
    //echo $sql;
    
while($row2 mysql_fetch_array($result2))
    {
    echo 
$row2['content'];
    echo 
" Page ".$row2['page_num']."</a></span><br /><br />\n";
    }
    
//mysql_close($con2);    
}
mysql_close($con);
?>
Reply With Quote

  #2 (permalink)  
Old 04-30-2008, 08:17 PM
curtiss's Avatar
Moderator
 
Join Date: May 2003
Posts: 1,445
Having a quick glance at the code, I believe your problem is a result of the fact that you failed to specify the "resource link identifier" in your mysql_query function calls.
PHP Code:
$result mysql_query($sql); 
should be:
PHP Code:
$result mysql_query($sql,$con); 
EDIT - I would also recommend echoing your SQL query as an HTML comment before you try to loop through the array. That way, if the SQL query does generate an error, you can try to look at the query to see if you can figure out what the error was.

If that doesn't help, then try replacing the "while" loop with an if statement. It would look something like:
PHP Code:
if($row mysql_fetch_array($sql2,$con2)) {
echo 
"OK";
}
else {
echo 
mysql_error();

Finally, and I just noticed this, but I'm a little confused about your methodology. Why are you opening two separate connection threads to the same database? You should be able to use $con for both SQL queries.

EDIT AGAIN - One more thing, and this has no bearing on the error you're encountering, but it really is necessary when working with PHP and MySQL.

If you're going to send information to the database that you're getting from some sort of user interaction (any POST or GET variables, basically), you really need to escape those items properly before sending them.

PHP Code:
$i $_GET['page_num']; 
should be:
PHP Code:
$i mysql_real_escape_string($_GET['page_num'],$con2); 
Have a look at the mysql_escape_string and mysql_real_escape_string functions in PHP. They could save you a lot of headaches in the future, if anyone ever tries to hack your site.
__________________
I hate Internet Explorer! Anyone with me?

Last edited by curtiss; 04-30-2008 at 08:33 PM.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
array and split warning in php gilgalbiblewhee Programming and Scripting 2 11-07-2007 02:19 PM


All times are GMT -5. The time now is 11:44 AM.

 
Bitrix
Clicky Web Analytics
CloudContacts
Maxtango


Subscribe to our feed | add to myYahoo!

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
© 1997-2007 HTMLCenter