I am trying to search for something in the database. However, this error keeps popping up. I was wondering if anyone could help me. Thanks

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?
$host = '127.0.0.1';
$database = 'lab11';
$conn = mysql_connect($host);
$select = mysql_select_db($database, $conn);
$user = $_POST['user'];
$pass = $_POST['pass'];
if (! $conn)
die("Couldn't connect to MySQL");
$query = 'SELECT * FROM `security` LIMIT 0 , 30';
$result = mysql_query($query, $conn);
$row = mysql_fetch_assoc($result);
$a = array_search($user, $row);
echo $a;

mysql_close($conn);
echo 'Hi ';
echo $user. '.' ;
echo ' I can see your password.';
echo ' It is ';
echo $pass;
?>
</body>
</html>

Recommended Answers

All 5 Replies

Hi there,
Have you tried running your sql statement straight through your SQL command interface (like phpMyAdmin). If that returns no errors, try adding some error catching as follows and check the results:

$query = 'SELECT * FROM `security` LIMIT 0 , 30';
$result = mysql_query($query, $conn);
if (mysql_numrows($result) > 0)
{
$row = mysql_fetch_assoc($result);
$a = array_search($user, $row);
echo $a;
} else {
echo "No rows returned";
}

Thanks for the help but the same error appears and the query works in sql. Is there any more actions that you can recommend me to fix this error?

Try this, it seems that the $result variable is set to NULL when you try and retrieve rows from it, if you are sure that your sql is correct, are you certain that you are connecting to your database correctly? I notice that you aren't passing a username or password to your mysql_connect() statement. But if that is also fine then try this:

$query = 'SELECT * FROM `security` LIMIT 0 , 30';
$result = mysql_query($query, $conn);
if (mysql_numrows($result) == 0)
{
echo "Result set is EMPTY";
} else if (!$result) {
echo "Result set is NULL";
} else {
echo "Result set is VALID";
$row = mysql_fetch_assoc($result);
$a = array_search($user, $row);
echo $a;
}

Apart from that, I'm pretty much out of ideas, hope this helps

Thanks for the help!!!
It worked finally. You were a great help

Swt, anytime

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.