Hi, I have made this simple script but I need to have it check if the balance is correct before it goes into negative. How can I add a line to do this, and what should be in this line? An example would be really good, as none are around for this specific function.
Here is the code as is. There are two files, so I can always make edits for different amounts.
<php code>
<? require ("tracker.php");
?>
<center>
<?php
include 'dbc.php';
?>
<title>J~Net Level Up</title>
<?php session_start();
$id = $_SESSION['user_id'];
// Connects to your Database
mysql_connect("localhost", "root", "pass") or die(mysql_error());
mysql_select_db("messages") or die(mysql_error());
$data = mysql_query("UPDATE `users` SET `balance` = `balance` - 1000 WHERE `users`.`id` =$id")
or die(mysql_error());
echo "<table border cellpadding=3>";
while($info = mysql_fetch_array( $data ))
{
echo "<tr>";
echo "<th>User:</th> <td>".$info['user_name'] . "</td> ";
echo "<th>Balance:</th> <td>".$info['balance'] . " </td></tr>";
}
echo "</table>";
// echo "Balance Is ".$_SESSION['balance'];
echo $row['user_name'] . " " . $row['balance'];
?>
<META HTTP-EQUIV=REFRESH CONTENT="0; URL=010101levup.php">
<end php code for page 1>
Page 2 does the magic afterwards. The first page is for sorting out the balance, and the second page only carries on after the balance amount has been validated by page 1, so doesn’t really needed to be added at this point.
Any ideas? Anyone, please help, if at all possible.
This should do as you wish, subtracts 1000 if the users balance > 0 else sets to 0