Can anyone help me solve this problem, i tried everthing and googled all over everything, but still cant find solution, i hope somebody help me, ty,
*sorry for my broken english

$db=mysql_connect ("localhost", "root") or die ('I cannot connect to the database because: ' . mysql_error()); 

$mydb=mysql_select_db("database");

$sql="SELECT ID, FirstName, LastName FROM `contacts` WHERE FirstName LIKE '%" . $name . "%' OR LastName LIKE '%" . $name ."%'";

$result=mysql_query($sql);

$numrows=mysql_num_rows($result);

echo "<p>" .$numrows . " results found for " . stripslashes($name) . "</p>"; 

while($row=mysql_fetch_array($result)){

    $FirstName =$row['FirstName'];
    $LastName=$row['LastName'];
    $ID=$row['ID'];

Your query is probably failing. You need some more error checking.

$db=mysql_connect ("localhost", "root") or die ('I cannot connect to the database because: ' . mysql_error()); 

$mydb=mysql_select_db("database");
if (!$mydb) {
    die ("Could not connect to database $mydb : " . mysql_error());
}

$sql="SELECT ID, FirstName, LastName FROM `contacts` WHERE FirstName LIKE '%" . $name . "%' OR LastName LIKE '%" . $name ."%'";

$result=mysql_query($sql)or die(mysql_error());

$numrows=mysql_num_rows($result);

echo "<p>" .$numrows . " results found for " . stripslashes($name) . "</p>"; 

while($row=mysql_fetch_array($result)){
    $FirstName =$row['FirstName'];
    $LastName=$row['LastName'];
    $ID=$row['ID'];

Just thought I would let you know also, the mysql_connect function is deprecated and is going to be removed in PHP 5.5 all together. So if you are using a version of PHP that supports mysqli_connect or PDO to use to connect to your database I would highly recommend using this instead.

ok, ill give it a try
thanks dude

ive changed it to mysqli_ but still with the same outcome

had the same problem earlier 2day..
include your password comment lines 10 to the end
replace with
mysql_query($sql)or die(mysql_error());

Hmmm. If the error check is on the query I would think it would have produced an error there.

Try this just to debug

<?php

$db=mysql_connect ("localhost", "root") or die ('I cannot connect to the database because: ' . mysql_error()); 

$mydb=mysql_select_db("database");
if (!$mydb) {
    die ("Could not connect to database $mydb : " . mysql_error());
}

$sql="SELECT ID, FirstName, LastName FROM `contacts` WHERE FirstName LIKE '%" . $name . "%' OR LastName LIKE '%" . $name ."%'";

$result=mysql_query($sql);
if (!$result) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $sql;
    die($message);
}
else
{

$row=mysql_fetch_array($result);

echo "<pre>";
var_dump($row);
echo "</pre>";

}

?>

Oh you changed to mysqli ..... and you are getting the same exact error? Post your code that you have now with mysqli_query

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.