HAHAHAHAHA! Lol, thanks....Silly typosZeroComp wrote:if (isset($_SESSION['palyer']))
theres your problem
Browser MMO Video #5
Re: Video#5
Coding - Unity3d JS, PHP, and small amount of C#.
Art stuff - GIMP, Blender
Art stuff - GIMP, Blender
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Video#5
Unfortunately, that is just one of the trade-offs for using a weakly-typed language like PHP. Strongly-typed languages such as C#, C, Java, etc. enforce you to declare your variables before use, which allows your IDE to easily tell you if you have mistyped a variable name (provided you have not mistyped it as the name of another declared variable). The benefit is that you have lots of various tricks you can use in weakly-typed languages that cannot be attempted in others.
The indelible lord of tl;dr
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Video#5
and you will really see the difference when you get to using javascript and php heavily together. Defining vars in one and not the other, mixing the . and + and other various things.
-
SpikedRocker
- Posts: 4
- Joined: Tue Jan 19, 2010 7:55 pm
Re: Video#5
I've updated my Paste-bin with one thing I found that was wrong, on my authenticate.php page I had it pointing to index.php, which I have yet to create, which I did make one to see if it would change something. It still directs at a blank page sitting with "authenticate.php?player=SpikedRocker&password=*******&submit=Login" like the GET method. Still not sure what else could be wrong but it does seem to be on the authenticate.php page. Still steaming forward with the tutorials hopefully someone sees something I don't.
Paste-bin page: http://abscured-vision-public.pastebin.com
UPDATE...I added some echo "Line #" ; lines into the different parts of the authenticate script to find where the script kicks out and it kicks out before
And doesn't make it to the next test echo line I inserted. So somewhere in there its kicking it out. I also get this error: "Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/s/p/i/spikedrocker/html/test/authenticate.php:1) in /home/content/s/p/i/spikedrocker/html/test/authenticate.php on line 3"
Paste-bin page: http://abscured-vision-public.pastebin.com
UPDATE...I added some echo "Line #" ; lines into the different parts of the authenticate script to find where the script kicks out and it kicks out before
Code: Select all
if (isset($_POST['submit']))
{
$player=$_POST['player'];
$password=$_POST['password'];
$player=strip_tags($player);
$password=strip_tags($password);
$password=md5($password);Re: Video#5
I've done something wrong
.
I can register and login just fine, but my password isn't masked. For some reason the mask="x" thingy doesn't work for me. Here's my code:
register.php
login.php
My next problem is really odd. When fighting a creature, my hit points never go down, no matter how many times the creature hits me. But the creature's hitpoints go down just fine (as far as I can tell the code for the player and creature is exactly the same, so I'm really puzzled).
battle.php
attack.php
Also, after I've killed both the goblin and the orc, the next battle returns an empty creature (no name or stats). Is it supposed to do that?
I hope somebody can tell me where I've messed up. Thanks muchly.
I can register and login just fine, but my password isn't masked. For some reason the mask="x" thingy doesn't work for me. Here's my code:
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" mask="x"><br>
ReType Password Again: <input type="text" name="pass2" size "15" mask="x"><br>
Type Email Address: <input type="text" name="email" size "60"><br>
<input type="submit" value="submit">Code: Select all
<form method="POST" action="authenticate.php">
Username <input type="text" name="player" size="21"><br>
Password <input type="text" name="password" size="21" mask="x">
<br>
<input type="submit" value="login" name="submit">battle.php
Code: Select all
<?php
include_once 'connect.php';
session_start();
if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
}
else
{
echo "Not Logged in <br><br> <A href='login.php'>Login</a>";
exit;
}
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
$playerhp = $playerinfo3['hpoints'];
$playerattack = $playerinfo3['attack'];
$playerdefense = $playerinfo3['defense'];
if (isset($_GET['creature']))
{
$creature=$_GET['creature'];
$creatureinfo="SELECT * from creatures where name = '$creature'";
$creatureinfo2=mysql_query($creatureinfo) or die("could not get the creature you were fighting!");
$creatureinfo3=mysql_fetch_array($creatureinfo2);
}
else
{
$creatureinfo="SELECT * from creatures order by rand() limit 1";
$creatureinfo2=mysql_query($creatureinfo) or die("could get a creature!");
$creatureinfo3=mysql_fetch_array($creatureinfo2);
}
$creature = $creatureinfo3['name'];
$creaturehp = $creatureinfo3['hpoints'];
$creatureattack = $creatureinfo3['attack'];
$creaturedefense = $creatureinfo3['defense'];
/////player info
echo "<u> " . $playerinfo3['name'] . "</u><br>";
echo "Hit points = " . $playerhp . "<br>";
echo "Attack = " . $playerattack . "<br>";
echo "Defense = " . $playerdefense . "<br><br><br>";
///////creature info
echo "<u> " . $creatureinfo3['name'] . "</u><br>";
echo "Hit points = " . $creaturehp . "<br>";
echo "Attack = " . $creatureattack . "<br>";
echo "Defense = " . $creaturedefense . "<br><br><br>";
echo "<a href='attack.php?creature=$creature'>Attack!";
?>Code: Select all
<?php
include_once 'connect.php';
session_start();
if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
}
else
{
echo "Not Logged in <br><br> <A href='login.php'>Login</a>";
exit;
}
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
if (isset($_GET['creature']))
{
$creature=$_GET['creature'];
$creatureinfo="SELECT * from creatures where name = '$creature'";
$creatureinfo2=mysql_query($creatureinfo) or die("could not get the creature you were fighting!");
$creatureinfo3=mysql_fetch_array($creatureinfo2);
}
else
{
echo "<a href='battle.php'>No Creature selected. Go Back!";
exit;
}
$playerhp = $playerinfo3['hpoints'];
$playerattack = $playerinfo3['attack'];
$playerdefense = $playerinfo3['defense'];
$creature = $creatureinfo3['name'];
$creaturehp = $creatureinfo3['hpoints'];
$creatureattack = $creatureinfo3['attack'];
$creaturedefense = $creatureinfo3['defense'];
///////////////////////players turn////////////////////
echo "<u> " . $playerinfo3['name'] . "'s Attack</u><br>";
$playerattack = rand(1,20) + $playerattack;
$creaturedefense = rand(1,20) + $creaturedefense;
echo $playerinfo3['name'] . "'s Attack roll is " . $playerattack . "<br>";
echo $creature . "'s defense roll is " . $creaturedefense. "<br>";
if ($playerattack > $creaturedefense)
{
echo $playerinfo3['name'] . " hits! <br>";
$playerdamage = rand(1,6);
$newcreaturehp = $creaturehp - $playerdamage;
echo "For " . $playerdamage . " points of damage. <br>";
if ($newcreaturehp < 1)
{
echo "The " . $creature . " has been killed";
$updatecreature="DELETE from creatures where name='$creature' limit 1";
mysql_query($updatecreature) or die("Could not update creature");
echo "<a href='battle.php'>Go Back";
exit;
}
$updatecreature="update creatures set hpoints='$newcreaturehp' where name='$creature' limit 1";
mysql_query($updatecreature) or die("Could not update creature");
}
else
{
echo $playerinfo3['name'] . " misses!<br>";
}
//////////////////////creatures turn //////////////////
echo "<u> " . $creature . "'s Attack</u><br>";
$creatureattack = rand(1,20) + $creatureattack;
$playerdefense = rand(1,20) + $playerdefense;
echo $creature . "'s Attack roll is " . $creatureattack . "<br>";
echo $playerinfo3['name'] . "'s defense roll is " . $playerdefense . "<br>";
if ($creatureattack > $playerdefense)
{
echo $creature . " hits! <br>";
$creaturedamage = rand(1,6);
$newplayerhp = $playerhp - $creaturedamage;
echo "For " . $creaturedamage . " points of damage. <br>";
if ($newplayerhp < 1)
{
echo $playerinfo3['name'] . " has been killed<br>";
echo "<a href='gameover.php'>Continue";
exit;
}
$updateplayer="update players set hpoints='$newplayerhp' where name='player1'";
mysql_query($updateplayer) or die("Could not update player");
}
else
{
echo $creature . " misses!";
}
echo "<br><br><a href='battle.php?creature=$creature'>Battle Again!";
?>I hope somebody can tell me where I've messed up. Thanks muchly.
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Video#5
I think I see why the player is taking no damage. In your UPDATE query to deposit the new player's hitpoint total, you are using this query:
However, you are setting up your player's name variable:
Either change the $_SESSION variable holder to $player1, or change your query script to $player. Right now your query is not finding anything, because it is looking for a name that holds "".
As for logging in and hiding the password, simply change your password input fields to:
If you set your input type to "password", it will automatically hide it.
Code: Select all
$updateplayer="update players set hpoints='$newplayerhp' where name='player1'";Code: Select all
if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
}As for logging in and hiding the password, simply change your password input fields to:
Code: Select all
<input type="password" ....>The indelible lord of tl;dr
Re: Video#5
You must have the eyes of a hawk, how on earth did you spot that errant 1? I've lost count of how many times I've gone over this code looking for the mistake, and I missed it every single time
.
Thankyou very, very much. You have fixed both issues for me
.
Onto the next tutorial!!!
Thankyou very, very much. You have fixed both issues for me
Onto the next tutorial!!!
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Video#5
Your very welcomeKismet wrote:You must have the eyes of a hawk, how on earth did you spot that errant 1? I've lost count of how many times I've gone over this code looking for the mistake, and I missed it every single time.
Thankyou very, very much. You have fixed both issues for me.
Onto the next tutorial!!!
In the future, a great way to help prevent these very-difficult-to-find query problems is to check your query right after it runs during testing. For example, right after you run your UPDATE query near the bottom of the script, you could alter your code like this:
Code: Select all
$updateplayer="update players set hpoints='$newplayerhp' where name='player1'";
mysql_query($updateplayer) or die("Could not update player");
//Remove after testing
$checkQuery="SELECT * from players where name='$player1'";
$holderQuery = mysql_query($checkQuery) or die("Could not check updated player HP");
$holderArray = mysql_fetch_assoc($holderQuery);
if($newplayerhp != $holderArray['hpoints']) {
echo "Error updating player hitpoints. Please check db and try again.";
exit;
}
The indelible lord of tl;dr
Re: Video#5
Thankyou Jackolantern. Up till now I've only ever used Python, which is very good at telling you where you messed up. PHP seems to be very different, if you make a mistake, you're pretty much left on your own to find it.
This is not such a bad thing methinks, cause I seem to learn more from making mistakes than the other way around
.
Anyway, thanks again for all your help.
This is not such a bad thing methinks, cause I seem to learn more from making mistakes than the other way around
Anyway, thanks again for all your help.
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Video#5
Yeah, most web development technologies really have to leave it up to you to find the bugs because you aren't testing inside an IDE. Some of the next-generation IDEs are starting to work on this however, with big companies like Zend claiming they are working on real in-IDE debugging including stepping, code-on-the-fly, etc.
The indelible lord of tl;dr