Video 9

Post all your tuts or request for tuts here.
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Video 9

Post by SpiritWebb »

Question:

If I don't want to add all the hpoints, spoints, etc. and just add the class name to their account when selecting their class, how can I do this? For example, I choose wizard and now in the database wizard was wrote the database. That way on the main page (index.php) I can display their race.
Image

Image
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: Video 9

Post by hallsofvallhalla »

this is solved in video 11 I think, i added the last part to classes in the last video.
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Video 9

Post by SpiritWebb »

I can't find it. Here is what I have:

reguser:

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

if ($email == "")
{
  echo "You didn't enter an 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 didn't enter a password";
    echo " <a href='register.php'>Go back</a>";
    exit;
  }
  else if($isplayer3 || strlen($player)>15 || strlen($player)<1)
  {
    print "There is already a player with that name or the name you specified is over 16 letters or less then 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 email address, please try again!<br>";
      echo " < a href='register.php'>Go back</a>";
      exit;
    }
    else
    {
      $password=md5($password);
      $racequery="SELECT * from races where name='$racechoice'";
      $racequery2=mysql_query($racequery) or die ("Could not load races.");
      $racequery3=mysql_fetch_array($racequery2);

      $SQL = "INSERT into players(name, password, email, reputation, rank, racechoice) VALUES ('$player','$password','$email','0','1','$racequery3[racechoice]','1')";
           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>";
?>
Register:

Code: Select all

 <link href="style.css" rel="stylesheet" type="text/css" />
<STYLE type="text/css">
 <!--
 BODY { background-image:url(registerscreenFinal.jpg);
               background-repeat:no-repeat;
               background-position:center;
               background-attachment:fixed }
 -->
</STYLE>
<body bgcolor="black">
<body text="white">
    <?php
    include 'connect.php';

    ?>
  <div id="reg">    <br><br><br><br><br>
    <form method ="post" action="reguser.php">
    Desired Username: <input type="text" name="player" size="21"><br><br>
    Desired Password: <input type="text" name="password" size "15"><br><Br>
    ReType Password: <input type="text" name="pass2" size "15"><br><br>
    Current Email Address: <input type="text" name="email" size "60"><br><br>


<?php
      print "Desired race: ";
      print "<select name='racechoice' length='20'>";
      $raceinfo="SELECT * from races";
      $raceinfo2=mysql_query($raceinfo) or die("Could not select races");
      while ($raceinfo3=mysql_fetch_array($raceinfo2))
      {
        print "<option>$raceinfo3[Name]</option>";
      }
      print "</select><br>";
?>
       <br>


      <Center>
    <input type="image" value="submit" src="buttons/register1.png"><a href="login.php"><img src="buttons/back.png" border="0">
      </center>

     </div>
    </form>
I'm wanting someone to be able to choose their race, then that race gets placed in the db in the players "racechoice field." Then in the db I can see what race they are "ie: human" and when they login, upper center shows their race type.

EDIT: When clicking register I get:
Notice: Undefined index: racechoice in C:\wamp\www\Mythuto\reguser.php on line 55
Could not register

line 55 is $SQL = "INSERT into ... "
Image

Image
User avatar
Torniquet
Posts: 869
Joined: Sun Aug 02, 2009 6:18 am

Re: Video 9

Post by Torniquet »

So do you want a drop down field with a list of the races??

I am farly sure that it is displayed in one of the videos...

do you need more of a tutorial or explination on how to use these??
New Site Coming Soon! Stay tuned :D
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: Video 9

Post by hallsofvallhalla »

change this
$SQL = "INSERT into players(name, password, email, reputation, rank, racechoice) VALUES ('$player','$password','$email','0','1','$racequery3[racechoice]','1')";
to

Code: Select all

$rchoice = $racequery3['racechoice'];
  $SQL = "INSERT into players(name, password, email, reputation, rank, racechoice) VALUES ('$player','$password','$email','0','1','$rchoice','1')";
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Video 9

Post by SpiritWebb »

hallsofvallhalla wrote:change this
$SQL = "INSERT into players(name, password, email, reputation, rank, racechoice) VALUES ('$player','$password','$email','0','1','$racequery3[racechoice]','1')";
to

Code: Select all

$rchoice = $racequery3['racechoice'];
  $SQL = "INSERT into players(name, password, email, reputation, rank, racechoice) VALUES ('$player','$password','$email','0','1','$rchoice','1')";

I tried, and still getting the undefined index racechoice.
Torniquet wrote:So do you want a drop down field with a list of the races??

I am farly sure that it is displayed in one of the videos...

do you need more of a tutorial or explination on how to use these??
I have the drop down menu already in my register screen. But say you go to register, and choose the human race. Well after you click register, I want the word, "Human" placed in the db under "racechoice."

Just like how we do the user name placed in the db, but their race choice is just being selected and placed in the db, rather then typing it.
Image

Image
User avatar
Torniquet
Posts: 869
Joined: Sun Aug 02, 2009 6:18 am

Re: Video 9

Post by Torniquet »

Never used a drop down. But this is how im sure it works...

Just liek you $_GET['data']; with the input text boxes.

you would do the same from your drop down menu.

$playerclass = $_GET['value from drop down'];

then when you run the mysql_query you insert the variable '$playerclass' just like other variables.

$query = mysql_query("INSERT INTO player_info (username, pclass) VALUES ('$username', '$playerclass')");

is as simple as that really.

Hope that helps ya
New Site Coming Soon! Stay tuned :D
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Video 9

Post by SpiritWebb »

Fixed it...I figured out where the problem was. Guess I just needed some "away" time from it. I had on $SQL = "INSERT into players..." The very end of that line, I had ,'1') wrote, and it wasn't being put anywhere. I removed it, tried it again, and it worked! :D
Image

Image
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Video 9

Post by SpiritWebb »

Now when I try the newly created person, it wont log in, keeps giving me wrong username or password, even though its right.
Image

Image
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: Video 9

Post by hallsofvallhalla »

are you converting your password on log in to md5 also?
Post Reply

Return to “Tutorials”