The Ace Posted April 19, 2008 Posted April 19, 2008 Right, I have been kinda testing the selling feature of houses, and I can't seem to sell houses that have prices such as 1e+15...the house price is an ordinary number in the estate.php, but in the database it is 1e+15. This is the error I get: QUERY ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'will=0,maxwill=100 WHERE userid=1' at line 1 Query was UPDATE users SET money=money+,will=0,maxwill=100 WHERE userid=1 Here is the query in the code: $db->query("UPDATE users SET money=money+{$np['hPRICE']},will=0,maxwill=100 WHERE userid=$userid"); It seems to be missing, in the error: {$np['hPRICE']} GRR! It is because the price of the house is 1e+15 and not the full, proper number, in the database... What I would like to know is, how do I get rid of the 1e+15 and all, and make it a proper layed out number? :cry: Quote
AlabamaHit Posted April 20, 2008 Posted April 20, 2008 Re: Database...Annoying! Post 10 Lines before and After that query....then I might be able to help... Quote
The Ace Posted April 21, 2008 Author Posted April 21, 2008 Re: Database...Annoying! OK, here are a few lines above and below that damn erroring (lol) query: $db->query("UPDATE users SET money=money-{$np['hPRICE']},will=0,maxwill={$np['hWILL']} WHERE userid=$userid"); echo "Congrats, you bought the {$np['hNAME']} for £{$np['hPRICE']}!"; } } else if (isset($_GET['sellhouse'])) { $npq = $db->query("SELECT * FROM houses WHERE hWILL={$ir['maxwill']}"); $np = $db->fetch_row($npq); if($ir['maxwill'] == 100) { echo "You already live in the lowest property!"; } else { $db->query("UPDATE users SET money=money+{$np['hPRICE']},will=0,maxwill=100 WHERE userid=$userid"); echo "You sold your {$np['hNAME']} and went back to your wooden hut."; } } else { echo "Your current property: [b]{$mp['hNAME']}[/b] The houses you can buy are listed below. Click a house to buy it. "; if($ir['maxwill'] > 100) { echo "[url='estate.php?sellhouse']Sell Your House[/url] "; } Quote
Haunted Dawg Posted April 21, 2008 Posted April 21, 2008 Re: Database...Annoying! Its called quotations ( ' & ' ) try them. $db->query("UPDATE users SET money='{$np['hPRICE']}',will=100,maxwill=100 WHERE userid='{$ir['userid']}'") or die(mysql_error()); Quote
Spudinski Posted April 21, 2008 Posted April 21, 2008 Re: Database...Annoying! Where are you getting the $np array from, and where is it declared? It looks like a simple typo, or maybe an invalid query somewhere else. Mind posting the parts where $np is mentioned as well? Quote
Guest Anonymous Posted April 21, 2008 Posted April 21, 2008 Re: Database...Annoying! Although, there is no need to quote that particular value assuming it has been correctly sanitized. Numeric values do not require to be quoted and as has been demonstrated elsewhere - blindly quoting can be a mistake. See: http://criminalexistence.com/ceforums/i ... ic=18686.0 Quote
The Ace Posted April 21, 2008 Author Posted April 21, 2008 Re: Database...Annoying! Its called quotations ( ' & ' ) try them. $db->query("UPDATE users SET money='{$np['hPRICE']}',will=100,maxwill=100 WHERE userid='{$ir['userid']}'") or die(mysql_error()); I did this, and I can sell the bigger houses, but I don't seem to get the money from selling it....grr. Where are you getting the $np array from, and where is it declared? It looks like a simple typo, or maybe an invalid query somewhere else. Mind posting the parts where $np is mentioned as well? Should I just post my estate page, with or without the update I did from killah? Quote
Spudinski Posted April 21, 2008 Posted April 21, 2008 Re: Database...Annoying! Before, as it was when you first posted for help. Quote
The Ace Posted April 21, 2008 Author Posted April 21, 2008 Re: Database...Annoying! OK, here is my original estate.php: <?php include "globals.php"; if($ir['jail'] or $ir['hospital']) { die("This page cannot be accessed while in jail or hospital."); } $mpq = $db->query("SELECT * FROM houses WHERE hWILL={$ir['maxwill']}"); $mp = $db->fetch_row($mpq); $_GET['property']=abs((float) $_GET['property']); if($_GET['property']) { $npq = $db->query("SELECT * FROM houses WHERE hID={$_GET['property']}"); $np = $db->fetch_row($npq); if($np['hWILL'] < $mp['hWILL']) { echo "You cannot go backwards in houses!"; } else if ($np['hPRICE'] > $ir['money']) { echo "You do not have enough money to buy the " . $np['hNAME']; } else { $db->query("UPDATE users SET money=money-{$np['hPRICE']},will=0,maxwill={$np['hWILL']} WHERE userid=$userid"); echo "Congrats, you bought the {$np['hNAME']} for £{$np['hPRICE']}!"; } } else if (isset($_GET['sellhouse'])) { $npq = $db->query("SELECT * FROM houses WHERE hWILL={$ir['maxwill']}"); $np = $db->fetch_row($npq); if($ir['maxwill'] == 100) { echo "You already live in the lowest property!"; } else { $db->query("UPDATE users SET money=money+{$np['hPRICE']},will=0,maxwill=100 WHERE userid=$userid"); echo "You sold your {$np['hNAME']} and went back to your wooden hut."; } } else { echo "Your current property: [b]{$mp['hNAME']}[/b] The houses you can buy are listed below. Click a house to buy it. "; if($ir['maxwill'] > 100) { echo "[url='estate.php?sellhouse']Sell Your House[/url] "; } $hq=$db->query("SELECT * FROM houses WHERE hWILL>{$ir['maxwill']} ORDER BY hWILL ASC"); while($r=$db->fetch_row($hq)) { echo "[url='estate.php?property={$r[']{$r['hNAME']}[/url]   - Cost: £" . number_format($r['hPRICE'], "") . "   - Will Bar: " . number_format($r['hWILL'], "") . " "; } } $h->endpage(); ?> Thanks... :) Quote
The Ace Posted April 27, 2008 Author Posted April 27, 2008 Re: Database...Annoying! Anyone able to help me....? Quote
Magictallguy Posted May 9, 2008 Posted May 9, 2008 Re: Database...Annoying! Try this: <?php include "globals.php"; if($ir['jail'] or $ir['hospital']) { die("This page cannot be accessed while in jail or hospital."); } $mpq = $db->query("SELECT * FROM houses WHERE hWILL={$ir['maxwill']}"); $mp = $db->fetch_row($mpq); $_GET['property']=abs((float) $_GET['property']); if($_GET['property']) { $npq = $db->query("SELECT * FROM houses WHERE hID={$_GET['property']}"); $np = $db->fetch_row($npq); if($np['hWILL'] < $mp['hWILL']) { echo "You cannot go backwards in houses!"; } else if ($np['hPRICE'] > $ir['money']) { echo "You do not have enough money to buy the " . $np['hNAME']; } else { $houseprice = ($np['hPRICE']); $db->query("UPDATE users SET money=money-$houseprice,will=0,maxwill={$np['hWILL']} WHERE userid=$userid"); echo "Congrats, you bought the {$np['hNAME']} for £{$np['hPRICE']}!"; } } else if (isset($_GET['sellhouse'])) { $npq = $db->query("SELECT * FROM houses WHERE hWILL={$ir['maxwill']}"); $np = $db->fetch_row($npq); if($ir['maxwill'] == 100) { echo "You already live in the lowest property!"; } else { $houseprice = ($np['hPRICE']); $db->query("UPDATE users SET money=money+$houseprice,will=0,maxwill=100 WHERE userid=$userid"); echo "You sold your {$np['hNAME']} and went back to your wooden hut."; } } else { echo "Your current property: [b]{$mp['hNAME']}[/b] The houses you can buy are listed below. Click a house to buy it. "; if($ir['maxwill'] > 100) { echo "[url='estate.php?sellhouse']Sell Your House[/url] "; } $hq=$db->query("SELECT * FROM houses WHERE hWILL>{$ir['maxwill']} ORDER BY hWILL ASC"); while($r=$db->fetch_row($hq)) { echo "[url='estate.php?property={$r[']{$r['hNAME']}[/url]   - Cost: £" . number_format($r['hPRICE'], "") . "   - Will Bar: " . number_format($r['hWILL'], "") . " "; } } $h->endpage(); ?> Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.