Page 1 of 1

code error?

Posted: Sat Jul 08, 2006 9:40 pm
by HomerTheDragoon
The error i get:
Parse error: parse error, unexpected T_STRING in /home/content/n/i/g/nightzer0/html/gmpets/login.php on line 17

Please help.

Code: Select all

<?
include("dbinfo.inc.php");
$username=$_POST['username'];
$password=$_POST['password'];
$login=0;

mysql_connect($hostname,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query="SELECT * FROM gmpets_accounts
$result=mysql_query($query);
$num=mysql_numrows($result);

$i=0;
while ($i<$num){
$dusername=mysql_result($result,$i,"username")
$dpassword=mysql_result($result,$i,"password")
if ($username==$dusername){
if ($password==$dpassword){

$stats[0]=mysql_result($result,$i,"strength");
$stats[1]=mysql_result($result,$i,"intelligence");
$stats[2]=mysql_result($result,$i,"agility");
$stats[3]=mysql_result($result,$i,"speed");
$stats[4]=mysql_result($result,$i,"defence");
$stats[5]=mysql_result($result,$i,"hp");
$pet=mysql_result($result,$i,"pet");
$login=1;}}
$i++}
if login=1{
echo "Strength: $stats[0]<br>";
echo "Intelligence: $stats[1]<br>";
echo "Agility: $stats[2]<br>";
echo "Speed: $stats[3]<br>";
echo "Defence: $stats[4]<br>";
echo "HP: $stats[5]<br>"
echo "Pet type: $pet";}
mysql_close();
?>

Posted: Sat Jul 08, 2006 9:42 pm
by dull1554

Code: Select all

$dusername=mysql_result($result,$i,"username")//add a semi colon here
$dpassword=mysql_result($result,$i,"password") //and here

Posted: Sat Jul 08, 2006 10:21 pm
by feyd
missing some quotes, as you may notice by the syntax highlighting looking wonky..

Posted: Sat Jul 08, 2006 10:30 pm
by dull1554
alltogether, error free (i think your code should look like this)

Code: Select all

<?php//Short tags should be avoided if possiable
include("dbinfo.inc.php");
$username=$_POST['username'];
$password=$_POST['password'];//also another security thing... i wouldnt pass your database usernae and password through the post variable..... not too hard to find out what it is, and i'd hate to see someone eff up ur database. If your intent was to define the persons username and password who was logging in you should change the names of these variables because your mysql_connect call is using this username and pass instead of the ones included in you dbinfo.inc.php file.
$login=0;

mysql_connect($hostname,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query="SELECT * FROM gmpets_accounts"; //missing a double quote and semi-colon.
$result=mysql_query($query);
$num=mysql_num_rows($result);//added a underscore to your function call, mysql_numrows does not exist.

$i=0;
while ($i<$num){
$dusername=mysql_result($result,$i,"username");//missing semi-colon;
$dpassword=mysql_result($result,$i,"password");//missing semi-colon;
if ($username==$dusername){
if ($password==$dpassword){

$stats[0]=mysql_result($result,$i,"strength");
$stats[1]=mysql_result($result,$i,"intelligence");
$stats[2]=mysql_result($result,$i,"agility");
$stats[3]=mysql_result($result,$i,"speed");
$stats[4]=mysql_result($result,$i,"defence");
$stats[5]=mysql_result($result,$i,"hp");
$pet=mysql_result($result,$i,"pet");
$login=1;}}
$i++}
if login=1{
echo "Strength: $stats[0]<br>";
echo "Intelligence: $stats[1]<br>";
echo "Agility: $stats[2]<br>";
echo "Speed: $stats[3]<br>";
echo "Defence: $stats[4]<br>";
echo "HP: $stats[5]<br>"
echo "Pet type: $pet";}
mysql_close();
?>

Posted: Sat Jul 08, 2006 11:06 pm
by hawleyjr
dull1554 wrote:alltogether, error free (i think your code should look like this)

Code: Select all

<?php//Short tags should be avoided if possiable
include("dbinfo.inc.php");
$username=$_POST['username'];
$password=$_POST['password'];//also another security thing... i wouldnt pass your database usernae and password through the post variable..... not too hard to find out what it is, and i'd hate to see someone eff up ur database. If your intent was to define the persons username and password who was logging in you should change the names of these variables because your mysql_connect call is using this username and pass instead of the ones included in you dbinfo.inc.php file.
$login=0;

mysql_connect($hostname,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query="SELECT * FROM gmpets_accounts"; //missing a double quote and semi-colon.
$result=mysql_query($query);
$num=mysql_num_rows($result);//added a underscore to your function call, mysql_numrows does not exist.

$i=0;
while ($i<$num){
$dusername=mysql_result($result,$i,"username");//missing semi-colon;
$dpassword=mysql_result($result,$i,"password");//missing semi-colon;
if ($username==$dusername){
if ($password==$dpassword){

$stats[0]=mysql_result($result,$i,"strength");
$stats[1]=mysql_result($result,$i,"intelligence");
$stats[2]=mysql_result($result,$i,"agility");
$stats[3]=mysql_result($result,$i,"speed");
$stats[4]=mysql_result($result,$i,"defence");
$stats[5]=mysql_result($result,$i,"hp");
$pet=mysql_result($result,$i,"pet");
$login=1;}}
$i++}
if login=1{
echo "Strength: $stats[0]<br>";
echo "Intelligence: $stats[1]<br>";
echo "Agility: $stats[2]<br>";
echo "Speed: $stats[3]<br>";
echo "Defence: $stats[4]<br>";
echo "HP: $stats[5]<br>"
echo "Pet type: $pet";}
mysql_close();
?>
Good Job, dull1554

Posted: Sun Jul 09, 2006 12:01 am
by HomerTheDragoon
now i get this error
Parse error: parse error, unexpected '}' in /home/content/n/i/g/nightzer0/html/gmpets/login.php on line 27

Code: Select all

<?php
include("dbinfo.inc.php");
$un=$_POST['username'];
$pw=$_POST['password'];//also another security thing... i wouldnt pass your database usernae and password ////through the post variable..... not too hard to find out what it is, 

///and i'd hate to see someone eff up ur database. If your intent was to define the persons username and ///password who was logging in you should change the names of these 

///variables because your mysql_connect call is using this username and pass instead of the ones included in you ///dbinfo.inc.php file.
$login=0;

mysql_connect($hostname,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query="SELECT * FROM gmpets_accounts"; //missing a double quote and semi-colon.
$result=mysql_query($query);
$num=mysql_num_rows($result);//added a underscore to your function call, mysql_numrows does not exist.

$i=0;
while ($i<$num){
$dusername=mysql_result($result,$i,"username");//missing semi-colon;
$dpassword=mysql_result($result,$i,"password");//missing semi-colon;
if ($un==$dusername && $pw==$dpassword){
$stats[0]=mysql_result($result,$i,"strength");
$stats[1]=mysql_result($result,$i,"intelligence");
$stats[2]=mysql_result($result,$i,"agility");
$stats[3]=mysql_result($result,$i,"speed");
$stats[4]=mysql_result($result,$i,"defence");
$stats[5]=mysql_result($result,$i,"hp");
$pet=mysql_result($result,$i,"pet");
$login=1;}}
$i++}
if login=1{
echo "Strength: $stats[0]<br>";
echo "Intelligence: $stats[1]<br>";
echo "Agility: $stats[2]<br>";
echo "Speed: $stats[3]<br>";
echo "Defence: $stats[4]<br>";
echo "HP: $stats[5]<br>"
echo "Pet type: $pet";}
mysql_close();
?>

Posted: Sun Jul 09, 2006 1:01 am
by Jenk
your if is incorrect..

Code: Select all

if ($login == 1) {

Posted: Sun Jul 09, 2006 6:52 am
by Ollie Saunders
Read the PHP manual on control structures and statement separation HomerTheDragoon. Unless you like been spoonfed.