PDA

View Full Version : Syntax problems...


mattd8752
01-21-2007, 01:03 PM
I'm getting:
Parse error: syntax error, unexpected '{' in /home/mattd/public_html/racing/purchase.php on line 43
on:

<?php
//PHP DB connect here
session_start();
mysql_connect("localhost", "mattd_rpg", "didyoureallyexpectmetogiveyouthis") or die("There was an error connecting to the mysql server.");
mysql_select_db("mattd_rpg");

$username=$_SESSION['username'];
$password=$_SESSION['password'];

$result=mysql_query("SELECT * FROM accounts WHERE username='$username' AND password='$password'");
if(mysql_num_rows($result) == 0){
die("Sorry, you are not logged in, please login again to continue playing. If you just signed in your username and/or password may be incorrect");
}else{
$query="select * from accounts";
$rt=mysql_query($query);
echo mysql_error();
while($nt=mysql_fetch_array($rt)){
if($nt[username] == $username){
echo $nt['username'].' '.$nt['money'].' '.$nt['email'].'<br>';
}
}
}
$cash = $nt[money];
//LOGIN CHECK MUST BE ADDED

$query="SELECT * FROM cars";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo "<b><center>Cars:</center></b><br><br>";

$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"id");
$name=mysql_result($result,$i,"name");
$hp=mysql_result($result,$i,"hp");
$price=mysql_result($result,$i,"price");
$owner==mysql_result($result,$i,"owner");
if(!isset($owner){
if($cash > $price){
echo "ID: <a href=\"purchase.php?buy=" . $id . "\">" . $id . "</a><br>Name:" . $name . "<br>HP:" . $hp . "<br>Sale Price:" . $price . "<br><br>";
}else{
echo "ID:" . $id . "<br>Name:" . $name . "<br>HP:" . $hp . "<br>Sale Price:" . $price . " (you can\'t afford this car)<br><br>";
}
}else{
echo "<br>This car is sold.<br>";//Testing purposes only
}
$i++;
}

?>
I don't quite get what the problem is, I have redone the and tried to look at the else & if statements many times, it just doesn't want to work. Any suggestions or fixes?

Brandoe85
01-21-2007, 01:09 PM
At quick glance, you missed a ')' here:
if(!isset($owner){

Should be:
if(!isset($owner)){

mattd8752
01-21-2007, 01:18 PM
TYVM, I rewrote that 2x and did it wrong both times...

I've got another problem now, with that fixed there are no syntax errors,

The page reads:
Matt 10000000 mrfg2006@gmail.com
Cars:


ID:1
Name:Mustang
HP:150
Sale Price:1 (you can\'t afford this car)

ID:2
Name:RustySpeed
HP:500
Sale Price:999999 (you can\'t afford this car)


EXACTLY what it should, except for 1 problem, I should be able to afford both cars. Instead of printing it with the link, it gives me the wrong if, I also tried reducing my cash so I had less, it isn't reversed, it simply is never calling the linked version if.

Brandoe85
01-22-2007, 04:51 PM
What do you get when you echo $cash and $price?

Lee Stevens
01-23-2007, 12:10 AM
Is your code like this?

if ($price <= $cash){
echo "( You can afford this car )";
} else {
echo "( you carnt afford this car )";
}

That should give you the crect result.