Jump to content

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given i


Recommended Posts

Have been confused for a while on this one. I am doing a little mini game as I want to make a game for me and my friends. So what I did was make a login and register.

 

<?php
if (isset($_POST['faction']))
{
$faction = $_POST['faction']; 
if ($_POST['username']&&$_POST['password']&&$_POST['email'])
{
$username = $_POST['username'];
$username = stripslashes($username);
$username = mysql_escape_string($username);
$password = $_POST['password'];
$password = stripslashes($password);
$password = mysql_escape_string($password);
$password = md5($password);
$email = $_POST['email'];
$email = stripslashes($email);
$email = mysql_escape_string($email);
mysql_connect("localhost","root","");
mysql_select_db("game");
$query = mysql_query("SELECT * FROM login WHERE username = '$username'");
$num = mysql_num_rows($query);
	if( $num == 0)
	{
	$query = mysql_query("INSERT INTO login(username,password,faction,email) VALUES('$username','$password','$faction','$email')");
	}
else
{ 
echo 
"That username is already taken.";
exit();
}
}
else
{
echo "You are missing a required field.";
exit();
}
}
else {
echo "You haven't selected a faction.";
exit();
}

$query = mysql_query("SELECT * FROM map WHERE uid='0' AND type='0' ORDER BY vid ASC LIMIT 0,1");

while($row = mysql_fetch_assoc($query));
{
$dbx = $row['x'];
$dby = $row['y'];
echo $dbx.$dby;
}
?>

It happens that the error is on line

 

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /opt/lampp/htdocs/game/registrationbackbone.php on line 45

 

Have been stumped on why.

Your query is failing and returning a boolean FALSE to mysql_fetch_assoc(). What happens if you paste the query string into phpMyAdmin? You should also incorporate logic to make sure the query executed without error.

Your query is failing and returning a boolean FALSE to mysql_fetch_assoc(). What happens if you paste the query string into phpMyAdmin? You should also incorporate logic to make sure the query executed without error.

So if I run that query through phpmyadmin it should give me what was wrong or what? As I don't know MySQL greatly as its new to me. I'll try that and keep you informed.

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.