Page 7 of 8

Re: Video#3

Posted: Wed Jun 09, 2010 4:46 am
by billysweird
Ok, this is the error im getting which is my own error i might add "Could Not Query Players table" and here's my code

Code: Select all

<?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 did not submit an email address!<br>";
  echo "<A href='register.php'>Go Back</a>";
  exit;
}
if ($password==$pass2)
#Needs to be player not Players|vvv|
{
  $isplayer="SELECT * from players where name ='$player'";
  $isplayer2=mysql_query($isplayer) or die("Could Not Query Players table");
  $isplayer3=mysql_fetch_array($isplayer2);
*FIXED* Found it took a while though

Re: Video#3

Posted: Wed Jun 09, 2010 5:12 am
by billysweird
Ok Double post BUT theres a new problem its not being entered into the DB.??

*edit* Solved it forgot to put the query after the SQL INPUT sequence.

Re: Video#3

Posted: Wed Jun 09, 2010 6:43 am
by Rastan
I see you have "#Needs to be player not Players|vvv|"

I don't know if that's what you fixed but below that in your link code you have "$isplayer="SELECT * from players" still an "s" there tho that might be what you said you fixed.

In the linked code you haven't yet put anything into the database. That reguser file checks input against the DB and if it doesn't find a match it goes to the code below which is that part that enters it in the database. if you have all that and its still not entering data then you may need to link the rest of what you have or clarify your question.

Code: Select all

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


Re: Video#3

Posted: Wed Jun 09, 2010 10:58 am
by billysweird
debugged and fixed em both Rastan :P.

I found out what the issue was with both of the first one the table name i had set was wrong and the second one i never put the query underneath the input array.

Re: Video#3

Posted: Sun Oct 31, 2010 11:19 am
by haakon023
im gettting something " database is not selected " when i did every thing the video said....and ive got it on all the others....

Re: Video#3

Posted: Tue Mar 29, 2011 2:18 pm
by drewcasey24
Hey everyone! im having a few errors wondering what could be wrong i copyed the codes directly from the source but can't figure out whats wrong.

errors:
Notice: Undefined index: password in C:\wamp\www\Tutorial\reguser.php on line 7
Notice: Undefined index: pass2 in C:\wamp\www\Tutorial\reguser.php on line 8
Notice: Undefined index: email in C:\wamp\www\Tutorial\reguser.php on line 10

reguser.php:
<?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";
echo " <A href='register.php'>Go back</a><br>";
exit;
}
else if($isplayer3 || strlen($player)>15 || 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<br>";
echo " <A href='register.php'>Go back</a>";
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<br>";
echo " <A href='register.php'>Go back</a>";
exit;
}
else
{
$password=md5($password);

$SQL = "INSERT into players(name, password, email, level, exper) VALUES ('$player','$password','$email','1','0')";
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<br>";
echo " <A href='register.php'>Go back</a>";
exit;
}
echo "<br><A href='login.php'>Login Page</a>";
?>

database pic:
tutorialdb.png

Re: Video#3

Posted: Tue Mar 29, 2011 8:51 pm
by PaxBritannia
Hi drewcasey24,

Welcome to indie-resource! :)


The reason that the errors are occurring is because you haven't checked to see if the variables exist before you use them.

For each of them, you need to create an if which checks to see if the variable is set

Code: Select all

if (isset($_POST['player']))
{
        $player=$_POST['player'];
}
Note however, that this is only a notice:
Notice: Undefined index: password in C:\wamp\www\Tutorial\reguser.php on line 7

This means that it isn't really an error, and the code works fine, but there are things you could do to the code which are considered good practice. You can just ignore these notices, and turn them off, just by inserting this into the top of your scripts:

Code: Select all

<?php error_reporting (E_ALL ^ E_NOTICE); ?>
Also, next time, try to use code tags: ;)

Code: Select all

[code]Your code goes in-between the tags
[/code]

pax.

Re: Video#3

Posted: Wed Mar 30, 2011 4:48 am
by drewcasey24
Thanks pax! One problem I'm brand new to php scripting so I'm following the tutorials to the t, but in the videos I did not see that used in the vid so I didn't do it, I have some scripting exp with pawno Anne I've noticed a lot of similarities. But where would this piece of code go, I even copy the code from the video and pasted it to no avail.

also i keep getting the

You didn't enter a email address!
Go back

no matter if i put one in or not even after putting in the code to ignore the notices

Re: Video#3

Posted: Wed Mar 30, 2011 5:46 am
by PaxBritannia
Nearly every scripting language look the same. :D
drewcasey24 wrote:But where would this piece of code go, I even copy the code from the video and pasted it to no avail.
Which piece of code exactly?

The code for the page generating the errors would help. ;)

pax.

Re: Video#3

Posted: Wed Mar 30, 2011 5:51 am
by drewcasey24

Code: Select all

if (isset($_POST['player']))
{
     $player=$_POST['player'];
}
EDIT:

Actually never mind i just fixed it, i found a mistake in the register.php changed it and it worked. but thanks for all the help.