Page 17 of 35

Re: Video#5

Posted: Sat Apr 03, 2010 9:57 pm
by hallsofvallhalla

Code: Select all

$query="select name,password from players where name= '$player' and '$password'";
should be

Code: Select all

$query="select name,password from players where name= '$player' and password='$password'";

Re: Video#5

Posted: Sun Apr 04, 2010 2:13 pm
by jskinman
thanx :lol:

battle.php code

Posted: Sun Apr 18, 2010 2:37 pm
by scape1027
what is the code for BATTLE.PHP?

Re: Video#5

Posted: Sun Apr 18, 2010 2:51 pm
by hallsofvallhalla
I stopped posting source for videos under 10. It is easier for everyone to watch at least to 10, I recommend watching until 14 or so then work with the code. Has nothing to do with learning abilities or anything, just easier to watch the early videos.

Re: Video#5

Posted: Sun Apr 18, 2010 4:04 pm
by scape1027
hallsofvallhalla wrote:I stopped posting source for videos under 10. It is easier for everyone to watch at least to 10, I recommend watching until 14 or so then work with the code. Has nothing to do with learning abilities or anything, just easier to watch the early videos.

well you see, when i log in, it says "Successfully Logged in" or something, and when I hit continue to go to the battle thing (video 5) it says

"Parse error: parse error in C:\wamp\www\tutorial\battle.php on line 7"

do you know whats wrong? and heres my code for lines 1 to 56

<?php
include '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!";

?>

Re: Video#5

Posted: Sun Apr 18, 2010 4:25 pm
by Jackolantern
It looks like your first if block is using parenthesis to create the block instead of brackets. Change:

Code: Select all

<?php
include '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'];
into:

Code: Select all

<?php
include 'connect.php';
session_start();

if (isset($_SESSION['player'])) //looks like you need to add the underscore here, too
{                                           //change to bracket. Parenthesis don't work here. 
     $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'];

Re: Video#5

Posted: Mon Apr 19, 2010 1:08 am
by scape1027
k thanks

Re: Video#5

Posted: Mon Apr 19, 2010 1:57 am
by scape1027

Re: Video#5

Posted: Mon May 03, 2010 4:41 am
by urmo252
I have 3 errors:( u can help me!!
Pictures:
Image
Image
Image


Code:
authenticate.php

Code: Select all

<?php
include_once 'coonetct.php';
session_start();

if (isset($_POST['submit']))
(
$player=$_POST['player'];
$password=$_POST['password'];
$player=strip_tags($player);
$player=strip_tags($password);
$password=md5($password);

$query="select name,password from players where name= '$player' and '$password'";
$result = mysql_query($query) or die("Could not query players");
$result2 = mysql_fetch_array($result);
if ($result2)
(
$_SESSION['player']=$player;

echo "<big>Logged in successfully<br>";
echo "<A href='battle.php'>Continue</a><big>";
)
else
(
echo "<big>Wrong Username or password.<A href='login.php'><Try again</a></big>";
)
)
?>


attack.php

Code: Select all

<?php
include 'connect.php';
session_start();

if (isset($SESSION['player']))
(
$player1=$_SESSION['player1'];
)
else
(
echo "Not Logged in <br><br> <A href='login.php'>Login</a>";
exit;
)
$playerinfo="SELECT * from players where name='player1'";
$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);

battle.php

Code: Select all

<?php
include 'connect.php';
session_start();

if (isset($SESSION['player']))
(
$player1=$_SESSION['player1'];
)
else
(
echo "Not Logged in <br><br> <A href='login.php'>Login</a>";
exit;
)
$playerinfo="SELECT * from players where name='player1'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);

$playerhp = $playerinfo3['htpoints'];
$playerattack = $playerinfo3['attack'];
$playerdefense = $playerinfo3['defense'];

Re: Video#5

Posted: Mon May 03, 2010 1:35 pm
by hallsofvallhalla
you ( ) are wrong should be { }

parentheses should be used in the if statement like

Code: Select all

if ($this == $that)
{


}
code blocks are used after that