<? 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", "") 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">
as you can see in above code it doesnt check if balance is available before it executes and balance goes into minus, is there a simple way it can have a if statement to make sure balance is available first before it executes the sql statement?
please help with this minor glitch what i need is a pro to edit the above code not tell me what lines needs to be added as before when this happens its untested and when i test it it fails so i need it to make sure balance is in there and if yes it goes to that refresh line (at bottom of code block),
and if there is insufficient funds it should return an error and not goto last line of code.
Please help if you can i can supply any sql you may need for this to test your end if required!
Add some extra logic to the where clause:
The update will still run, but only actually change the record if the balance is high enough to begin with.