0

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'];
3
Contributors
8
Replies
25
Views
4 Years
Discussion Span
Last Post by pixelsoul
0

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'];
0

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.

0

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

0

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>";

}

?>
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.