Jump to content
MakeWebGames

Recommended Posts

Posted

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:

Posted

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]
";
}
Posted

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?

Posted

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?

Posted

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] &nbsp - Cost: £" . number_format($r['hPRICE'], "") . " &nbsp - Will Bar: " . number_format($r['hWILL'], "") . "
";
}
}
$h->endpage();
?>

 

Thanks... :)

  • 2 weeks later...
Posted

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] &nbsp - Cost: £" . number_format($r['hPRICE'], "") . " &nbsp - Will Bar: " . number_format($r['hWILL'], "") . "
";
}
}
$h->endpage();
?>

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...