mattd8752 Posted January 21, 2007 Share Posted January 21, 2007 Parse error: syntax error, unexpected '{' in /home/mattd/public_html/racing/purchase.php on line 43on:[code]<?php//PHP DB connect heresession_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 More sharing options...
trq Posted January 21, 2007 Share Posted January 21, 2007 [code=php:0]if(!isset($owner){[/code]should be...[code=php:0]if(!isset($owner)) {[/code] Link to comment https://forums.phpfreaks.com/topic/35086-syntax-problems-what-a/#findComment-165581 Share on other sites More sharing options...
mattd8752 Posted January 21, 2007 Author Share Posted January 21, 2007 Ok, now I've got 1 more problem,The page reads:Matt 10000000 [email][email protected][/email]Cars:ID:1Name:MustangHP:150Sale Price:1 (you can\'t afford this car)ID:2Name:RustySpeedHP:500Sale 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. Link to comment https://forums.phpfreaks.com/topic/35086-syntax-problems-what-a/#findComment-165585 Share on other sites More sharing options...
paul2463 Posted January 21, 2007 Share Posted January 21, 2007 here is your problem[code]<?php$cash = $nt[money];?>[/code]this line should read[code]<?php$cash = $nt['money'];?>[/code] Link to comment https://forums.phpfreaks.com/topic/35086-syntax-problems-what-a/#findComment-165599 Share on other sites More sharing options...
mattd8752 Posted January 21, 2007 Author Share Posted January 21, 2007 Ok, I've just ditched that part of code (for now) it will just show a link. Anyway,I will post back if I have any more problems with this script.And that isn't the problem, as I have echoed $cash and it comes out.Thanks for everyone who tried to help. Link to comment https://forums.phpfreaks.com/topic/35086-syntax-problems-what-a/#findComment-165601 Share on other sites More sharing options...
paul2463 Posted January 21, 2007 Share Posted January 21, 2007 also this line[code]<?php$owner==mysql_result($result,$i,"owner");?>[/code]should read[code]<?php$owner=mysql_result($result,$i,"owner"); //only one equals sign?>[/code] Link to comment https://forums.phpfreaks.com/topic/35086-syntax-problems-what-a/#findComment-165606 Share on other sites More sharing options...
mattd8752 Posted January 21, 2007 Author Share Posted January 21, 2007 Thanks, that does need fixing. Link to comment https://forums.phpfreaks.com/topic/35086-syntax-problems-what-a/#findComment-165610 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.