Subtract From and Update mysql database field via php

Hello Peeps,
I am trying to do the following

  1. receive input via a form
  2. From the submitted variables, check the email in the database table and then pick the number field i want to subtract from
  3. subtract the value from the submitted form from the value in the amount field in the database (I want to verify that the submitted value is less than the value in the database field)
  4. Update the database with the value of the subtraction…
  5. redirect to another page

I have written a script but i’m not sure if it will work… I need experienced php programmers to please take a look and modify if necessary… Thank you for your time and kind consideration…
The script is below


$host=“localhost”; // Host name
$username=“root”; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name

//Connect to server and select databse.
mysql_connect("$host", “$username”, “$password”)or die(“cannot connect to server”);
mysql_select_db("$db_name")or die(“cannot select DB”);

// value sent from form

// table name

// retrieve password from table where e-mail = $Email([email protected])
$sql=“SELECT account_balance FROM $tbl_name WHERE email=’$Email’”;
mysql_query(“UPDATE client SET account_balance = ‘$result - $val’
WHERE email=’$Email’”);

header(“Location: Processingpage1.htm”);


Sponsor our Newsletter | Privacy Policy | Terms of Service