Page 1 of 1

PHP & MySQL help

Posted: Mon Jun 08, 2009 9:54 pm
by dubtrice
Hi I am having a problem with a code I am trying to write, ive got what looks (to me) like a good code, but apparently its faulty because all I get is the white screen when I try to load it on my server.

Its for a game I am making, I want it to check the "users" (specific userid) sql table and take away however many herbs ('crystals') the user enters into the field box (from the specific users table), then create a random number and multiply that number by the number of herbs. The resulting number will then be added to their 'money' field in the users table. It sounds simple enough, but im a complete php noob so im finding it very difficult, this is also the first php code ive ever compiled.

Code: Select all

<?php
session_start();
require "global_func.php ";
if($_SESSION['loggedin']==0) { header("Location: login.php");exit; }
$userid=$_SESSION['userid'];
require "header.php";
$h = new headers;
$h->startheaders();
include "mysql.php";
global $c;
$is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",$c ) or die(mysql_error());
$ir=mysql_fetch_arra y($is);
check_level();
$fm=money_formatter( $ir['money']);
$lv=date('F j, Y, g:i a',$ir['laston']);
$h->userdata($ir,$lv,$f m);
$maxsell=$ir['crystals'];
print "Sell your herbs";
if ($_GET['herbs'])
{
if ($_GET['herbs']>$maxsell) 
{
die("You don't have that many herbs<br>
<a href=herbs.php>go back</a>");
}
else if ($_GET['herbs']<1)
{
die("You can't sell someone nothing<br>
<a href=herbs.php>go back</a>");
}
$random=(int) rand(200,1800)*$_GET['herbs'];
$earned=$random;
print "You sold $_GET['herbs'] herbs for \$$earned ";
mysql_query("UPDATE users SET money=money+({$earned}) where userid=$userid", $c);
mysql_query("UPDATE users SET crystals=crystals-({$_Get['herbs']}) where userid=$userid", $c);
}
else
{
print "Sell Your Herbs<br />
You can sell no more than $maxsell herbs.<br />
<form action='herbs.php' method='get'>
Sell: <input type='text' name='herbs' value='0' /><br />
<input type='submit' value='Sell' />
</form>";
}
 
$h->endpage();
?>
Are there any errors with my coding? If you need more information, please let me know!

Re: PHP & MySQL help

Posted: Mon Jun 08, 2009 10:43 pm
by requinix

Code: Select all

print "You sold $_GET['herbs'] herbs for \$$earned ";
Either it's missing the {}s or you added apostrophes where they don't belong - your choice.

Re: PHP & MySQL help

Posted: Mon Jun 08, 2009 11:17 pm
by dubtrice
What part, could you be more specific?

Re: PHP & MySQL help

Posted: Mon Jun 08, 2009 11:23 pm
by requinix
More specific than quoting the exact line of code?

Re: PHP & MySQL help

Posted: Tue Jun 09, 2009 7:44 pm
by dubtrice
yea man this is the first code ive ever put together..

you mean like this?

print {You sold $_GET['herbs'] herbs for \$$earned };

or

print "You sold {$_GET[herbs]} herbs for \$$earned ";

or something else?

ive tried both and still get a blank page :(

Re: PHP & MySQL help

Posted: Tue Jun 09, 2009 7:52 pm
by requinix
Apostrophes. They have just one little mark, not two.

You have three options:

Code: Select all

print "You sold " . $_GET['herbs'] . " herbs for \$$earned "; // not in the string
print "You sold $_GET[herbs] herbs for \$$earned "; // no apostrophes
print "You sold {$_GET['herbs']} herbs for \$$earned "; // braces

Re: PHP & MySQL help

Posted: Tue Jun 09, 2009 8:12 pm
by dubtrice
okay thanks, ill try it out!