Jump to content

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in


probir

Recommended Posts

i am try to make a name, address search system into my website from my database. but i got this msg [Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampplite\htdocs\3\searchresult.php on line 54]

 

my full php code i.e. searchresult.php is under......

 

what i have mistake.....

 

searchresult.php

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?php

// TAKE THE INFORMATION FROM FORM.

$search = $_GET['search'];

// IF THERE IS NOT A KEYWORD GIVE A MISTAKE.

if (!$search)

echo "You didn't enter a keyword";

else

{

echo "<td>You searched for: <strong>$search </strong></td>";

mysql_connect('localhost','root','');

mysql_select_db('search');

$id=@$_GET['id'];

//QUERY IS THE CODE WHICH WILL MAKE THE SEARCH IN YOUR DATABASE.

//I WROTE AN EXPLANATION ABOUT IT AFTER THE CODE.

$sql = "CREATE TABLE searchform \n"
    ."(\n"
    ."ID int NOT NULL AUTO_INCREMENT ,\n"
    ."FirstName varchar( 255 ) NOT NULL ,\n"
    ."LastName varchar( 255 ) NOT NULL ,\n"
    ."Email varchar( 255 ) NOT NULL ,\n"
    ."PhoneNumber varchar( 255 ) NOT NULL ,\n"
    ."PRIMARY KEY ( ID ) )";;

$result1 = MySQL_query($query);

if(!$result1) {

echo MySQL_error()."<br>$query<br>";

}

if(MySQL_num_rows($result1) > 5) {

echo "<table width='750' align='center' border='0' cellspacing='0' cellpadding='0'>";

while($result2 = MySQL_fetch_array($result1)) {

//A short description from category.

$description = $result2['category'];

$searchPosition = strpos($description, $search);

$shortDescription = substr($description, $searchPosition, 150);

// I added a link to results which will send the user to your display page.

echo '<tr><td><p><strong><a href="displayresults.php?id='.$result2['id'].'">'.$result2['title'].'</strong></p></td></tr>';

echo "<tr><td>$shortDescription ...</td></tr>";

echo "<td>{$result2['name']} {$result2['surname']}</td><tr/>";

}

echo "</table>";

}else {

echo "No Results were found in this category.<br>";

}echo "<br>";

}

?>

</body>
</html>

 

and

 

searchform.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form action="searchresult.php" method="get">

<div align="center">

<p>

<input name="search" type="text" size="60"/>

<input name="submit" type="submit" value="Search" />

</p>

</div>

</form>
</body>
</html>

Link to comment
Share on other sites

This database query does not search for anything. It creates a new database table, as "CREATE TABLE" would imply . . .

 

$sql = "CREATE TABLE searchform \n"
    ."(\n"
    ."ID int NOT NULL AUTO_INCREMENT ,\n"
    ."FirstName varchar( 255 ) NOT NULL ,\n"
    ."LastName varchar( 255 ) NOT NULL ,\n"
    ."Email varchar( 255 ) NOT NULL ,\n"
    ."PhoneNumber varchar( 255 ) NOT NULL ,\n"
    ."PRIMARY KEY ( ID ) )";;

Link to comment
Share on other sites

I'm surprised your query isn't failing! You are trying to run the query in the variable $query - but it hasn't been defined. Instead you defined the query in the variable $sql.

 

But, I am confused as to why you would be running mysql_num_rows() against the result since the query is to CREATE a table, so I don't see how there would be any rows returned.

Link to comment
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.