Jump to content

[SOLVED] Mysql error


ngreenwood6

Recommended Posts

I have the following page:

 

<?php
//include the variables
include("includes/variables.php");

//define the variable from the form
$username = strtolower($_POST['username']);

//connect to the database
$connect = mysql_connect($host,$user,$pass) or die("could not connect");

//select the database
$select_db = mysql_select_db($db);

//query for the database
$query = "SELECT * FROM $table WHERE username = '$username'";

//get the results
$results = mysql_query($query);

//number the rows
$num_rows = mysql_num_rows($results);

if ($num_rows == 1)
{
//put it into an array
$row = mysql_fetch_array($results);
}

//give the username a variable
$row_username = $row['username'];

//if the username is not in the database
if($num_rows < 1)
{
echo "That username is not in the database!";
}


?>

 

Whenever I submit the form I get this error:

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\check_user.php on line 21

 

Any ideas why?

Link to comment
https://forums.phpfreaks.com/topic/127065-solved-mysql-error/
Share on other sites

[quote author=AndyB link=topic=219574.msg1006417#msg1006417 date=1223166510]
Change:
[code]$results = mysql_query($query);

 

to:

$results = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);

 

That should explain what's going on/going wrong.[/code]

Link to comment
https://forums.phpfreaks.com/topic/127065-solved-mysql-error/#findComment-657317
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.