Page 1 of 2

Find the Error!! Yay!!

Posted: Sat Feb 05, 2005 11:19 am
by SilverMist
Hey guys!
This code is for users to purchase a horse on my virtual reality horse game. The error I'm getting is an unexpected '=' on line 69. Anyone want to figure this out?

Code: Select all

<?php 
// For register_global on PHP settings
$member = $_COOKIE&#1111;'member'];

session_start(); // you must put this to read session variables

if (empty($member) || !isset($member)) // fail to read the browser cookie
&#123;
// Try to read session
if (empty($_SESSION&#1111;'member']) || !isset($_SESSION&#1111;'member']))
&#123;
header("Location: log.php"); // redirect user to login
exit;
&#125;
else
&#123;
$member = $_SESSION&#1111;'member'];
&#125;
&#125;

// MySQL Connection Variables 
// Fill in your values for the next 4 lines
$hostname='localhost';
$user='*******'; //'user name for MySQL database';
$pass='*****'; //'Password for database'; 
$dbase='*************'; //'database name';

$connection = mysql_connect("$hostname" , "$user" , "$pass") or die ("Can't connect to MySQL");
$db = mysql_select_db($dbase , $connection) or die ("Can't select database.");

// User has login but you should check his account validity again
$qChk = "select id from members where uname='$member' and status='Y' ";
$rsChk = mysql_query($qChk);

if (mysql_num_rows($rsChk) != '1')
&#123;
header("Location: log.php");
exit; 
&#125;
?><?php include('top.php'); ?>Purchase Horse<?php include('next2.php'); ?>Purchase Horse<?php include('middle.php'); ?>
<?php
//Script © Kate MacDougall
//It is for purchasing horses on a SIM game called Equinique
//She worked her butt off to make, steal it and she'll not be very pleased
//Thanks and have a great day :-p
// MySQL Connection Variables 
// Fill in your values for the next 4 lines
$hostname='localhost';
$user='********'; //'user name for MySQL database';
$pass='******'; //'Password for database'; 
$dbase='********'; //'database name';

$connection = mysql_connect("$hostname" , "$user" , "$pass") or die ("Can't connect to MySQL");
$db = mysql_select_db($dbase , $connection) or die ("Can't select database.");
//The following are the variables sent from the horse.php page where the user clicked a button, agreeing to purchase the horse. They're hidden, soooo....
$price = $_POST&#1111;'price'];
$name = $_POST&#1111;'name'];
//This is the thing to see how many horses a user has
$q = mysql_query("SELECT * FROM horses WHERE owner='$uname'");
$g = mysql_num_rows($q);
//The following gets the amount of money a user has.
$money = ("SELECT * FROM members WHERE uname='$uname' AND money='$money'");
$cmon = mysql_query($money);
//Next check how many horses a user has
if($g>=20)&#123;
die("You have too many horses, and you cannot own more.");
&#125;
//Purchase the horse and set the owner to the name, meaning that the horse was previously owned, not a horse created by the game, which would be "Unowned".
if($g<=20 && $money>=$price && owner='$owner')
&#123;
//Subtract the price from the member....
$updateone = ("UPDATE * TABLE members WHERE uname='$member' SET $money - $price");
$uptwo = mysql_query($updateone);
//Give the old owner the money
//When they bought the horse it set fowner as being their name
//Fowner will change below
$pay = ("UPDATE * TABLE horses SET $fowner + $price");
$p = mysql_query($pay); 
//Set fowner to member
$updatetwo = ("UPDATE * TABLE horses SET owner='$member' and fowner='$member'");
$upthree = mysql_query($updatetwo);
//Tell 'em the good news... 
echo "You've purchased this horse!";
&#125;
//This is the script for horses who are Unowned, as in created by the game. This is different because Unowned isn't actually an account, so we cannot give it money.
if($g<=20 && $money>=$price && owner='Unowned')
&#123;
//Subtract the money...
$updateone = ("UPDATE * TABLE members WHERE uname='$member' SET $money - $price");
$uptwo = mysql_query($updateone);
//Make it fowner
$updatetwo = ("UPDATE * TABLE horses SET owner='$member' and fowner='$member'");
$upthree = mysql_query($updatetwo);
//Tell them they've purchased.
echo "You've purchased this horse!";
&#125;
//This is incase they don't have enough money to purchase the horse.
if($g<=20 && $money<=$price)
&#123;
echo "You don't have enough to purchase this horse.";
&#125;
//I wasn't totally sure what to put here, so....
else
&#123;
echo "Whoops, contact technical support, somethings gone wrong!";
&#125;
?>

Posted: Sat Feb 05, 2005 11:37 am
by feyd
it would have been helpful to tell us which line 69 was.. at any rate both 69 and 86 of your posted code would appear to have logic errors.. = vs == issues.. I don't see it creating an error though..

also, the strings are literals, are you sure you wanted to set the variables to a literal of their name?

Posted: Sat Feb 05, 2005 11:38 am
by MrKnight
incorrect

Code: Select all

... owner='Unowned'
correct

Code: Select all

... $owner='Unowned'
same thing in the line 86..

don't know if it will fix it but that is how you should do, shouldnt you?

Posted: Sat Feb 05, 2005 11:44 am
by SilverMist
Okay, well, did that, and now the page comes up but I get:
You've purchased this horse!You've purchased this horse!Whoops, something's gone wrong, contact technical support!
And when I go to my view horses page the horse isn't there, so apparantely it isn't updating somewhere. I can't find it, can anyone else?

Posted: Sat Feb 05, 2005 11:47 am
by feyd
what do those lines look like now?

Re: Find the Error!! Yay!!

Posted: Sat Feb 05, 2005 12:21 pm
by Jade
You might want to consider the following Silva:

Code: Select all

<?php
/***********
Script © Kate MacDougall and design1online.com
It is for purchasing horses on a SIM game called Equinique 
She worked her butt off to make, steal it and she'll not be very pleased 
Thanks and have a great day :-p 
**********/

session_start(); //this should always go first
$member = $_COOKIE&#1111;'member'];

/***************
i suggest using sessions instead
not all computers will accept cookies and this will just end up giving you login errors in my experience
********************/

if (!$member) //not logged in, take them to login page
&#123;
header("Locaiton: log.php");
exit;
&#125;

include('../../dbconnect.php');

/***********
You should NEVER include your database login on your php pages.
Instead make a page called something like dbconnect.php and put it OUTSIDE your public_html folder so that only your server can access it and no one else. This prevents hackers. This is what should go in the dbconnect.php file:

// MySQL Connection Variables 
// Fill in your values for the next 4 lines 
$hostname='localhost'; 
$user='*******'; //'user name for MySQL database'; 
$pass='*****'; //'Password for database'; 
$dbase='*************'; //'database name'; 

$connection = mysql_connect("$hostname" , "$user" , "$pass") or die ("Can't connect to MySQL"); 
$db = mysql_select_db($dbase , $connection) or die ("Can't select database."); 

****************/

include('top.php'); 
echo "Purchase Horse";
include('next2.php'); 
echo "Purchase Horse";
include('middle.php');

//variables from horse.php

$price = $_POST&#1111;'price']; 
$name = $_POST&#1111;'name']; 

//Question for you, where is $uname coming from???
//That could give you a problem
//if you make your variable names better then its easier
//to figure out what is going on

//This is the thing to see how many horses a user has 
$query = mysql_query("SELECT * FROM horses WHERE owner='$uname'") or die ('there was an error: ' mysql_error()); 

$numhorses = mysql_num_rows($query); 

//The following gets the amount of money a user has. 
$query = ("SELECT money FROM members WHERE uname='$uname'") or die ('cannot selec users money: ' mysql_error()); 

$row = mysql_fetch_array($result);
$money = $row&#1111;'money'];

if($numhorses >=20)
   die("You have too many horses, and you cannot own more."); 

//Purchase the horse and set the owner to the name
//meaning that the horse was previously owned, not a
//horse created by the game, which would be "Unowned". 

if($numhorses < 20 && ($money - $price) > 0 && $owner !='Unowned') 
&#123; 

//update members money
mysql_query("UPDATE members SET money = $money - $price WHERE uname='$member'") or die ('cannot give member money: ' mysql_error()); 

//Give the old owner the money 
//You need the name of the old owner here...
//where are you getting that above??
//you need to get oldowner and set it as $oldowner

mysql_query("UPDATE members SET money=money+$price WHERE uname='$oldowner") or die ('cannot old owner money: ' mysql_error()); 
 

//Set fowner to member 
mysql_query ("UPDATE horses SET owner='$member' and fowner='$member'") or die ('cannot give horse new owner: ' mysql_error()); 

&#125; //end horse already has an owner

//This is the script for horses who are Unowned,
//as in created by the game. This is different because 
//Unowned isn't actually an account, so we cannot give it money. 

else if($numhorses < 20 && ($money - $price) > 0 && $owner == 'Unowned') 
&#123; 
//Subtract the money... 
mysql_query ("UPDATE members SET money=money-$price WHERE uname='$member'") or die ('cannot give member money: ' mysql_error()); 

//Make it fowner 
mysql_query("UPDATE horses SET owner='$member' and fowner='$member'") or die ('cannot give horse new owner: ' mysql_error()); 

//Tell them they've purchased. 
echo "You've purchased this horse!"; 
&#125; 
//This is incase they don't have enough money to purchase the horse. 
else if (($money - $price) < 0) 
&#123; 
echo "You don't have enough to purchase this horse."; 
&#125;
?>

Posted: Sat Feb 05, 2005 12:23 pm
by MrKnight
how you understand if horse is owned or not? i couldnt figure it out

Posted: Sat Feb 05, 2005 12:24 pm
by MrKnight
ow, that is?

Posted: Sat Feb 05, 2005 12:27 pm
by Jade
She sets the horse as being "unowned" if it doesn't have a current owner. A little confusing in my opinnion. Would be easier to track the users by an ID number and horses with no owner would get 0 as their owner's ID -- meaning they don't have one. There are a few more variables she needs to pick up before this code will work as I pointed out in my suggestion.

Posted: Sat Feb 05, 2005 12:31 pm
by MrKnight
my question was first script, second is clear
and btw, that is, first is second's imitation or more? :o

Posted: Sat Feb 05, 2005 12:34 pm
by Jade
MrKnight wrote:and btw, that is, first is second's imitation or more? :o
I'm not sure I understand your question. Are you asking if my script is immitating hers?

Posted: Sat Feb 05, 2005 12:36 pm
by MrKnight
no, hers,silva's, i meant :?
maybe i should not have called it so

Posted: Sat Feb 05, 2005 12:39 pm
by Jade
Oooh, I understand you now. No, her's isn't copying mine. I added my design1online.com link to the top of her script beacuse I basically rewrote the entire thing. That way I still get credit. :D

Posted: Sat Feb 05, 2005 12:43 pm
by MrKnight
oh, good job.
very nice
(and also sorry for turning here kinda irc place)

Posted: Sat Feb 05, 2005 8:27 pm
by SilverMist
Okay using Jade's script all I get is a blank screen. Anyone know what is wrong?