Reguser.php Could not query players table

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
Eddy Parera
Posts: 18
Joined: Mon Feb 06, 2012 7:54 pm

Reguser.php Could not query players table

Post by Eddy Parera »

My code is the same that you made without the class stuff. But when I register like you do, I receive an error, Could not query players table. Also, mysql is equal to yours.

And I can't find why it can't query that table.

Thank you.

This is my code, can you check it please?

Code: Select all

<?php
include 'connect.php';
?>

<?php
$player=$_POST['player'];
$password=$_POST['password'];
$pass2=$_POST['pass2'];
$player=strip_tags($player);
$email=$_POST['email'];
$email=strip_tags($email);

if ($email == "")
{
echo "You didn't enter a email address!<br>";
echo " <A href='register.php'>Go back</a>";
exit;
}
if ($password==$pass2)
{

$isplayer="SELECT * from players where name='$player'";
$isplayer2=mysql_query($isplayer) or die("Could not query players table");
$isplayer3=mysql_fetch_array($isplayer2);

if(!$_POST['password'] || !$_POST['pass2'])
{
print "You did not enter a password<br>";
echo " <A href='register.php'>Go back</a>";
exit;
}
else if($isplayer3 || strlen($player)>21 || strlen($player)<1)
{
print "There is already a player of that name or the name you specified is over 16 letters or less than 1 letter";
echo " <A href='register.php'>Go back</a><br>";
exit;
}
else
{
$isaddress="SELECT * from players where email='$email'";
$isaddress2=mysql_query($isaddress) or die("not able to query for password");
$isaddress3=mysql_fetch_array($isaddress2);
if($isaddress3)
{
print "There is already a player with that e-mail address";
echo " <A href='register.php'>Go back</a><br>";
exit;
}
else
{
$password=md5($password);

$SQL = "INSERT into players(name, password, email, level, exper, attack, defense, hpoints, maxhp, spoints, maxspoints,pclass) VALUES ('$player','$password','$email','1','0','$classquery3[attack]','$classquery3[defense]','$classquery3[hpoints]','$classquery3[hpoints]','$classquery3[spoints]','$classquery3[spoints]','$classquery3[name]')";
mysql_query($SQL) or die("could not register");

print "Thank you for registering!";

}
}
}

else
{
print "Your password didn't match or you did not enter a password";
echo " <A href='register.php'>Go back</a><br>";
exit;
}
 echo " <A href='login.php'>Login Page</a><br>";
?>
My MYsql printscreen:
Image
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Reguser.php Could not query players table

Post by SpiritWebb »

if ($password==$pass2)
{

$isplayer="SELECT * from players where name='$player'";
$isplayer2=mysql_query($isplayer) or die("Could not query players table");
$isplayer3=mysql_fetch_array($isplayer2);
At the end of the ("Could not query players table") add this:

Code: Select all

("Could not query players table" . mysql_error())";  // This will display any errors from MYSQL and will help better understand what is going on
Image

Image
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: Reguser.php Could not query players table

Post by Chris »

You've called your field 'nickname' and are trying to fill 'name'. attack, defense, hpoints, maxhp, spoints, maxspoints, pclass aren't even there.

Code: Select all

$SQL = "INSERT INTO players (nickname, password, email, level, exper) VALUES ('$player','$password','$email','1','0');";
mysql_query($SQL) or die("could not register");
 
Fighting for peace is declaring war on war. If you want peace be peaceful.
Eddy Parera
Posts: 18
Joined: Mon Feb 06, 2012 7:54 pm

Re: Reguser.php Could not query players table

Post by Eddy Parera »

It appeared like this.

Code: Select all

Could not query players tablemysql_error()
I fixed the code as it should be, but it presents the same error.

I have also added a "power" item, on mysql and on the php page.

Code: Select all

<?php
include 'connect.php';
?>

<?php
$player=$_POST['player'];
$password=$_POST['password'];
$pass2=$_POST['pass2'];
$player=strip_tags($player);
$email=$_POST['email'];
$email=strip_tags($email);

if ($email == "")
{
echo "You didn't enter a email address!<br>";
echo " <A href='register.php'>Go back</a>";
exit;
}
if ($password==$pass2)
{

$isplayer="SELECT * from players where name='$player'";
$isplayer2=mysql_query($isplayer) or die("Could not query players table" . "mysql_error()");  // This will display any errors from MYSQL and will help better understand what is going on
$isplayer3=mysql_fetch_array($isplayer2);

if(!$_POST['password'] || !$_POST['pass2'])
{
print "You did not enter a password<br>";
echo " <A href='register.php'>Go back</a>";
exit;
}
else if($isplayer3 || strlen($player)>21 || strlen($player)<1)
{
print "There is already a player of that name or the name you specified is over 16 letters or less than 1 letter";
echo " <A href='register.php'>Go back</a><br>";
exit;
}
else
{
$isaddress="SELECT * from players where email='$email'";
$isaddress2=mysql_query($isaddress) or die("not able to query for password");
$isaddress3=mysql_fetch_array($isaddress2);
if($isaddress3)
{
print "There is already a player with that e-mail address";
echo " <A href='register.php'>Go back</a><br>";
exit;
}
else
{
$password=md5($password);

$SQL = "INSERT INTO players (nickname, password, email, level, exper, power) VALUES ('$player','$password','$email','1','0','10');";
mysql_query($SQL) or die("could not register");


print "Thank you for registering!";

}
}
}

else
{
print "Your password didn't match or you did not enter a password";
echo " <A href='register.php'>Go back</a><br>";
exit;
}
 echo " <A href='login.php'>Login Page</a><br>";
?>
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: Reguser.php Could not query players table

Post by Chris »

You want to call mysql_error() as a function.

You have:

Code: Select all

$isplayer2=mysql_query($isplayer) or die("Could not query players table" . "mysql_error()"); 
Should be:

Code: Select all

$isplayer2=mysql_query($isplayer) or die("Could not query players table" . mysql_error() ); 
Fighting for peace is declaring war on war. If you want peace be peaceful.
Eddy Parera
Posts: 18
Joined: Mon Feb 06, 2012 7:54 pm

Re: Reguser.php Could not query players table

Post by Eddy Parera »

now it says the problem
Could not query players tableUnknown column 'name' in 'where clause'
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: Reguser.php Could not query players table

Post by Chris »

As I said before. You've called your field/column 'nickname' and are making a comparison to 'name' (which doesn't exist).

Code: Select all

$isplayer="SELECT * from players where name='$player'"; 
Shoule be:

Code: Select all

$isplayer="SELECT * FROM players WHERE nickname = '$player'"; 
Fighting for peace is declaring war on war. If you want peace be peaceful.
Eddy Parera
Posts: 18
Joined: Mon Feb 06, 2012 7:54 pm

Re: Reguser.php Could not query players table

Post by Eddy Parera »

Ohh thanks a lot, I'm a newbie. And sorry to bother you.
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: Reguser.php Could not query players table

Post by Chris »

No problem ;) Check my previous post because I saw another problem in your script.
Fighting for peace is declaring war on war. If you want peace be peaceful.
Eddy Parera
Posts: 18
Joined: Mon Feb 06, 2012 7:54 pm

Re: Reguser.php Could not query players table

Post by Eddy Parera »

Yeah, I have already fixed it.
Post Reply

Return to “Beginner Help and Support”