Jump to content

Recommended Posts

hi! i  badly need your help.. i'm having an error in my addressbook system..

 

Here's the error:

mysql_num_rows() expects parameter 1 to be resource, null given in /Applications/XAMPP/xamppfiles/htdocs/sampol3/design/edit.php on line 74.

 

 

please give the right code.. thank you..

17348_.php

Link to comment
https://forums.phpfreaks.com/topic/255046-help-me-please/
Share on other sites

Firstly, I haven't looked at your code because I won't download code.

 

Anyway, your error is very common and is caused by passing the results of a call to mysql_query() straight into mysql_num_rows() without first checking to see that your query has succeeded.

 

mysql_num_rows() expects a result resource, while mysql_query() will return a result resource on success or the boolean false on failure.

 

For some reason, your query is failing. What does mysql_error have to say?

Link to comment
https://forums.phpfreaks.com/topic/255046-help-me-please/#findComment-1307785
Share on other sites

here' the function for mysql_error():

 

mysql_error($con)

 

 

$con=mysql_connect("localhost",$username,$password);

if(!$con)

die("couldn't connect to MySQL: ".mysql_error());

 

mysql_select_db($db_name,$con)

or die("couldn't connect to $db_name: ".mysql_error());

 

Link to comment
https://forums.phpfreaks.com/topic/255046-help-me-please/#findComment-1307796
Share on other sites

Try adding or die(mysql_error()) to the end of your mysql_fetch_array() call like this:

 

mysql_fetch_array($query) or die(mysql_error());

 

This will give you a more precise definition of the problem.

 

Or better still, handle your errors properly.

 

An example:

 

if ($result = mysql_query($sql)) {
  if (mysql_num_rows($result)) {
    // $result is now good to use
  } else {
    // no results found
  }
} else {
  trigger_error(mysql_error());
}

Link to comment
https://forums.phpfreaks.com/topic/255046-help-me-please/#findComment-1307800
Share on other sites

switch($select)

{

case 1:

$result=mysql_query("SELECT * FROM tb_addressbook WHERE lastname LIKE'%$text%'");

break;

case 2:

$result=mysql_query("SELECT * FROM tb_addressbook WHERE firstname='$text'");

break;

case 3:

$result=mysql_query("SELECT * FROM tb_addressbook WHERE address='$text'");

break;

}

 

 

 

if (!$result=)

{

echo "Could not successfully run query ($result) from database" . mysql_error($con);

 

}

 

if (mysql_num_rows($result) == 0)  //(im having a problem in this line.

{

 

echo "<br>No rows found, Please try again! <br>

<a href='searchform.php'>search</a>";

echo "<br><br>";

exit;

}

Link to comment
https://forums.phpfreaks.com/topic/255046-help-me-please/#findComment-1307801
Share on other sites

While your problem is with your query you have a logic issue here.

 

if (!$result=)
   {
   echo "Could not successfully run query ($result) from database" . mysql_error($con);
   
   }

 

If $result is false you echo an error message. this is good, however, you never stop your code from going into the next part:

 

if (mysql_num_rows($result) == 0)  

 

If $result is false, you will always get an error here because (as I have already explained) mysql_num_rows expects a result resource. Nothing else can be passed to it.

Link to comment
https://forums.phpfreaks.com/topic/255046-help-me-please/#findComment-1307816
Share on other sites

This code seems familiar.

 

Wizzle, you already bumped an old thread with a post to add this or very similar code, where I relied what is causing the symptom and what you needed to do to troubleshoot what is causing the problem - http://www.phpfreaks.com/forums/index.php?topic=272971.msg1658897#msg1658897

Link to comment
https://forums.phpfreaks.com/topic/255046-help-me-please/#findComment-1307849
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.