Jump to content

Syntax problems... What a...


mattd8752

Recommended Posts

Parse error: syntax error, unexpected '{' in /home/mattd/public_html/racing/purchase.php on line 43
on:
[code]
<?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++;
}

?>[/code]
I don't quite get what the problem is, I have redone the and tried to look at the else statements many times, it just doesn't want to work.
Link to comment
https://forums.phpfreaks.com/topic/35086-syntax-problems-what-a/
Share on other sites

Ok, now I've got 1 more problem,


The page reads:
Matt 10000000 [email][email protected][/email]
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.