Page 1 of 1

help please

Posted: Tue Feb 14, 2012 1:00 am
by pretender5552
Does anyone remember the could you can put into or die so that it will tell you why it doesn't work rather then a custom message, the coder makes?

Re: help please

Posted: Tue Feb 14, 2012 1:45 am
by pretender5552

Code: Select all

$playerinfo="SELECT * from player where name='bryan'";
I need this cause when I took out bryan an put in the variable $player it keeps telling me variable is undefined.

Re: help please

Posted: Tue Feb 14, 2012 2:51 am
by SpiritWebb
You would use:

Code: Select all

mysql_error();
example:

Code: Select all

$sql = mysql_query("SELECT * FROM players WHERE name='$player'") or die("Could not select from players" . mysql_error());

Re: help please

Posted: Tue Feb 14, 2012 3:08 am
by pretender5552
Thanks for some reason it says that undefined variable: player in line 8

Code: Select all

<?php
include 'connect.php';
?>
<div id="div2">
<link href="style.css" rel="stylesheet" type="text/css"/>

<?php
$playerinfo="SELECT * from player where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die((mysql_error()));
$playerinfo3=mysql_fetch_array($playerinfo2);

$player = $playerinfo3['name'];
$playerhealth = $playerinfo3['health'];
$playertech = $playerinfo3['tech'];
$playerenergy = $playerinfo3['energy'];
$playermaxhealth = $playerinfo3['maxhealth'];
$playermaxtech = $playerinfo3['maxtech'];
$playermaxenergy = $playerinfo3['maxenergy'];
$playermoney = $playerinfo3['credit'];

echo "<table border='1' cellspacing='0' bordercolor=green><tr><td bgcolor='000000'>";
echo "<font color='000000'>" . "&nbsp&nbsp&nbsp&nbsp" . "</font><font size='4'><font color='ffffff'><b> " . $playerhealth . "</font><font color='ffff99'> / " . $playermaxhealth . "<font color='000000'>" . "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</font></font>";
echo "<font color='ffffff'>" . $playertech . "</font><font color='ffff99'>/" . $playermaxtech . "<font color='000000'>" . "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</font></font>";
echo "<font color='ffffff'>" . $playerenergy . "<font color='ffff99'>/" . $playermaxenergy . "<font color='000000'>" . "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</font></font>";
echo "<font color='ffffff'>$" . $playermoney . "</b></font></font><font color='000000'>" . "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<br>";
echo "<font color='000000'>" . "&nbsp&nbsp&nbsp&nbsp&nbsp" . "<font size='1'><font color='ffff99'><b>HEALTH</font>";
echo "<font color='000000'>" . "______________" . "<font size='1'><font color='ffff99'><b>TECH</font>";
echo "<font color='000000'>" . "____________" . "<font size='1'><font color='ffff99'><b>ENERGY</font>";
echo "<font color='000000'>" . "__________" . "<font size='1'><font color='ffff99'><b>CREDIT</font>";
echo "</td></tr></table>";

?>
</div>

<div id= "experiencebar">

<?php
echo "<img src='images/barback.PNG'>";

?>
</div>

<div id= "experience">

<?php
$width = ($playerinfo3['experience'] / $playerinfo3['experienceneeded']) * 105;
echo "<img src='images/redliquid.gif' width='$width' height='19' >";
?>
</div>

Re: help please

Posted: Tue Feb 14, 2012 4:25 am
by Jackolantern
Its undefined because...you haven't defined it ;) Unless you set the $player variable in your connect.php script, or there is something above that you didn't include, that is your problem. You need to set $player before you can use it in your query.

Re: help please

Posted: Tue Feb 14, 2012 5:05 am
by pretender5552
Got it put in

Code: Select all

<?php
include 'connect.php';
session_start();
?>
<div id="div2">
<link href="style.css" rel="stylesheet" type="text/css"/>

<?php
if (isset($_SESSION['player']))
{
  $player=$_SESSION['player'];
}
else
{
  echo "Not Logged in <br><br> <A href='login.php'>Login</a>";
  exit;
}

Re: help please

Posted: Tue Feb 14, 2012 6:04 am
by pretender5552
But a new problem arises for some reason when I try to register another character I get this warning Could not register.Column count doesn't match value count at row 1

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'];

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 player 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 player 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 class where class='$classchoice'";
  $classquery2=mysql_query($classquery) or die("Could not query classes" . mysql_error());
  $classquery3=mysql_fetch_array($classquery2);

$SQL = "INSERT into player(id, name, password, email, level, experience, class, health, maxhealth, tech, maxtech, energy, maxenergy, attack, defence, credit, experienceneeded) VALUES ('','$player','$password','$email','1','0','$classquery3[class]','$classquery3[health]','$classquery3[maxhealth]','$classquery3[tech]','$classquery3[maxtech]','$classquery3[maxenergy]','$classquery3[attack]','$classquery3[defense]','0','30')";
mysql_query($SQL) or die ("Could not register." . mysql_error());

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 please

Posted: Tue Feb 14, 2012 6:31 am
by SpiritWebb
You forgot to add the energy, you added the maxtech and maxenergy, but forgot the energy, so its not lining up correctly.

Re: help please

Posted: Tue Feb 14, 2012 6:39 am
by pretender5552
ah jeez how did I not see that.

Thanks

Re: help please

Posted: Tue Feb 14, 2012 6:55 am
by pretender5552
For some reason whenever I try to log on as anyone other then test it says wrong username or password though they are spelled correctly


id name health experience tech level credit energy attack defence maxhealth maxenergy maxtech experienceneeded group addstat cypher image win lose class ranking datereg password email
Edit Inline Edit Copy Delete 1 Bryan 10 5 5 1 10000 5 1 1 10 5 5 30 0 0 0 0 0 0 Hacker 1 0000-00-00 00:00:00 nowayout
Edit Inline Edit Copy Delete 0 test 15 0 10 1 0 10 5 5 15 10 10 30 0 0 0 0 0 0 0 2012-02-12 23:07:21 098f6bcd4621d373cade4 test
Edit Inline Edit Copy Delete 2 Trance 15 0 10 1 0 10 5 5 15 10 10 30 0 0 0 0 0 0 Modder 0 2012-02-13 23:45:04 b52e2935287a1f4fe1923 pretender5552@hotmail

Code: Select all

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

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

   $query = "select name,password from player 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='home.php'>Continue</a></big>";
   }
   else
   {
    echo "<big>Wrong username or password.<a href='login.php'>Try Again</a></big>";
   }
}
?>