PHP & MySQL help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dubtrice
Forum Newbie
Posts: 4
Joined: Mon Jun 08, 2009 8:00 pm

PHP & MySQL help

Post 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!
Last edited by Benjamin on Tue Jun 09, 2009 11:18 pm, edited 1 time in total.
Reason: Added [code=php] tags.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP & MySQL help

Post 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.
dubtrice
Forum Newbie
Posts: 4
Joined: Mon Jun 08, 2009 8:00 pm

Re: PHP & MySQL help

Post by dubtrice »

What part, could you be more specific?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP & MySQL help

Post by requinix »

More specific than quoting the exact line of code?
dubtrice
Forum Newbie
Posts: 4
Joined: Mon Jun 08, 2009 8:00 pm

Re: PHP & MySQL help

Post 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 :(
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP & MySQL help

Post 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
dubtrice
Forum Newbie
Posts: 4
Joined: Mon Jun 08, 2009 8:00 pm

Re: PHP & MySQL help

Post by dubtrice »

okay thanks, ill try it out!
Post Reply