code error?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
HomerTheDragoon
Forum Newbie
Posts: 21
Joined: Sat Jul 08, 2006 2:10 am

code error?

Post 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();
?>
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

Code: Select all

$dusername=mysql_result($result,$i,"username")//add a semi colon here
$dpassword=mysql_result($result,$i,"password") //and here
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

missing some quotes, as you may notice by the syntax highlighting looking wonky..
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post 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();
?>
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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
HomerTheDragoon
Forum Newbie
Posts: 21
Joined: Sat Jul 08, 2006 2:10 am

Post 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();
?>
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

your if is incorrect..

Code: Select all

if ($login == 1) {
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Read the PHP manual on control structures and statement separation HomerTheDragoon. Unless you like been spoonfed.
Post Reply