title: mysql balance check amount exists before going into minus balance
body: <p>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.</p>
  
  <p>Here is the code as is. There are two files, so I can always make edits for different amounts.</p>
  
  <pre><code>&lt;php code&gt;
  
  
  &lt;? require ("tracker.php");
  
  ?&gt;
  
  
  &lt;center&gt;
  &lt;?php 
  include 'dbc.php';
  
  
  ?&gt;
  &lt;title&gt;J~Net Level Up&lt;/title&gt;
   &lt;?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 "&lt;table border cellpadding=3&gt;"; 
   while($info = mysql_fetch_array( $data )) 
  { 
   echo "&lt;tr&gt;"; 
   echo "&lt;th&gt;User:&lt;/th&gt; &lt;td&gt;".$info['user_name'] . "&lt;/td&gt; "; 
   echo "&lt;th&gt;Balance:&lt;/th&gt; &lt;td&gt;".$info['balance'] . " &lt;/td&gt;&lt;/tr&gt;"; 
   } 
   echo "&lt;/table&gt;";
   // echo "Balance Is ".$_SESSION['balance']; 
  echo $row['user_name'] . " " . $row['balance'];
   ?&gt;
  &lt;META HTTP-EQUIV=REFRESH CONTENT="0; URL=010101levup.php"&gt;
  
  &lt;end php code for page 1&gt;
  </code></pre>
  
  <p>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.</p>
  
  <p>Any ideas? Anyone, please help, if at all possible.</p>