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();
?>