Page 1 of 1

Help

Posted: Sat Apr 28, 2012 11:57 pm
by Kintama
Hey all so i am trying to add a gender option on my browser game but i keep getting
Notice: Undefined index: gender in C:\xampp\htdocs\UltimateNinja\reguser.php on line 13
could not register
i have looked at the code and can not find any think wrong with it. i do not no what i am doing wrong
this is the code

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);
$classchoice=$_POST['classchoice'];
$genderchoice=$_POST['genderchoice'];
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);

 //////////////////////////////new for video 9//////////////
 $classquery="SELECT * from classes where name='$classchoice'";
  $classquery2=mysql_query($classquery) or die("Could not query classes");
  $classquery3=mysql_fetch_array($classquery2);
  $genderquery="SELECT * from gender where gender='$genderchoice'";
  $genderquery2=mysql_query($genderquery) or die("Could not query gender");
  $genderquery3=mysql_fetch_array($genderquery2);

$SQL = "INSERT into players(name, password, email, level, exper, attack, defense, hpoints, maxhp, spoints, maxspoints,pclass,gender) VALUES ('$player','$password','$email','1','0','$classquery3[attack]','$classquery3[defense]','$classquery3[hpoints]','$classquery3[hpoints]','$classquery3[spoints]','$classquery3[spoints]','$classquery3[name]','$genderquery3[gender]'";
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>";
?>

Re: Help

Posted: Sun Apr 29, 2012 2:49 am
by Ark
make sure that the input's name property is "genderchoice" e.g <input name="genderchoice" /> ...

Re: Help

Posted: Sun Apr 29, 2012 1:22 pm
by hallsofvallhalla
correct, you are getting this error because it is not being sent over. Check your register.php page for errors in the gender choice section.

Re: Help

Posted: Sun Apr 29, 2012 7:39 pm
by Kintama
Hey thanks that fixed the Error Problem but now i get
"Could not query genders" when i try to register
reguser.php

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);
$classchoice=$_POST['classchoice'];
$genderchoice=$_POST['genderchoice'];


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

 //////////////////////////////new for video 9//////////////
  $classquery="SELECT * from classes where name='$classchoice'";
  $classquery2=mysql_query($classquery) or die("Could not query classes");
  $classquery3=mysql_fetch_array($classquery2);
  /////////////////////////////////gender/////////////////////////////
  $genderquery="SELECT * from genders where name='$genderchoice'";
  $genderquery2=mysql_query($genderquery) or die("Could not query genders");
  $genderquery3=mysql_fetch_array($genderquery2);
  ////////////////////////////////////////////////////////////////////
  
$SQL = "INSERT into players(name, password, email, level, exper, attack, defense, hpoints, maxhp, spoints, maxspoints, pclass, pgender,) VALUES ('$player','$password','$email','1','0','$classquery3[attack]','$classquery3[defense]','$classquery3[hpoints]','$classquery3[hpoints]','$classquery3[spoints]','$genderquery3[pgender]')";
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>";
?>
register.php

Code: Select all

<?php
include 'connect.php';

?>

<form method ="post" action="reguser.php">
Type Username Here: <input type="text" name="player" size="21"><br>
Type Password Here: <input type="text" name="password" size "15"><br>
ReType Password Again: <input type="text" name="pass2" size "15"><br>
Type Email Address: <input type="text" name="email" size "60"><br>

<input type="submit" value="submit">
 

 <?php
      print "<select name='classchoice' length='20'>";
      $classinfo="SELECT * from classes";
      $classinfo2=mysql_query($classinfo) or die("Could not select classes");
      while ($classinfo3=mysql_fetch_array($classinfo2))
      {
        print "<option>$classinfo3[name]</option>";
      }
      print "</select><br>";
?>

 <?php
      print "<select name='genderchoice' length='20'>";
      $genderinfo="SELECT * from genders";
      $genderinfo2=mysql_query($genderinfo) or die("Could not select genders");
      while ($genderinfo3=mysql_fetch_array($genderinfo2))
      {
        print "<option>$genderinfo3[gendersel]</option>";
      }
      print "</select><br>";
?>

</form>
<?php

      print "<center><h3>Class Starting modifiers</h3></center>";
      print "<center>";
      print "<table border='0' width='70%' cellspacing='20'>";
      print "<tr><td width='25%' valign='top'>";
      print "</td>";
      print "<td valign='top' width='75%'>";
      $selectclass="SELECT * from classes";
      $selectclass2=mysql_query($selectclass) or die("could not select Classes");
      print "<table border='1' bordercolor='black' bgcolor='#ffffff'>";
      print "<tr><td><font color='cc0033'>Class<font color='ffffff'>_____________</td><td><font color='cc0033'>Attack<font color='ffffff'>_</font><td><font color='cc0033'>Defense<font color='ffffff'>_</font></td><td><font color='cc0033'>Hit Points<font color='ffffff'>_</font></td><td><font color='cc0033'>Spell Points<font color='ffffff'>_</font></td></tr>";
      while($selectclass3=mysql_fetch_array($selectclass2))
      {
       print "<tr><td>$selectclass3[name]</td><td>$selectclass3[attack]</td><td>$selectclass3[defense]</td><td>$selectclass3[hpoints]</td><td>$selectclass3[spoints]</td></tr>";
          
      }
      print "</table>";
      print "</td></tr></table>";    
      print "</center>";
    
    
?>
this is the code for both of them i don't see Any think wrong with them

Re: Help

Posted: Sun Apr 29, 2012 8:45 pm
by Foofighter
check if genderchoice has a value, cant find anything that seems to be wrong

Re: Help

Posted: Mon Apr 30, 2012 2:13 am
by hallsofvallhalla
make sure you have a table called genders and it has a field called name.

Re: Help

Posted: Tue May 01, 2012 7:43 pm
by Kintama
Thanks for the help guys finally got it working :)

Re: Help

Posted: Thu May 03, 2012 6:59 pm
by hallsofvallhalla
glad you got it working. Also make sure you label your topics other than "Help" so others can quickly find posts to answer their own issues without having to check every "Help" or "Whats wrong with my code" labeled posts ;)