- On the below code up to echo $AA it works! The echo shows the $rec['totsb'] minus 1 correctly, subtracting 1 from the existing value in the database. Then I need to save the new number generated after reducing one back to the database which is where my code is for sure is wrong. I tried many alternatives to correct it but couldn't get through. Can some one tell me how to save the new number back to the database?
info: my database looks like below. And as you see in between numbers are populated in a drop down to be selected by the user.(database has only starting 302 and end as 309, drop down has all 302,303,304...309) So if a user picks 306 for instance it should automatically identify in between which start and end number 306 fits in and save the new number as appropriate in totsb.
+--------+---------+------+
|sbstart |sbend | totsb|
+--------+---------+------+
|302 |309 | 8 |
|200 |208 | 9 |
|405 |409 | 5 |
+--------+---------+------+
Code:
<?php
$con=mysql_connect('localhost','root') or die ("Server connection failure!");
$db=mysql_select_db('regional_data',$con) or die ("Couldn't connect the database");
$SQL="SELECT * FROM newchk";
$run=mysql_query($SQL,$con) or die ("SQL Error");
$nor=mysql_num_rows($run);
while ($rec = mysql_fetch_array($run))
{
for($i=$rec['sbstart']; $i<=$rec['sbend']; $i++)
{
$opt=$_POST['options'];
if($i = $opt)
{
if($rec['totsb'] <= "0")
{
echo "You have already entred this cheque number.";
return false;
} else {
echo "You can proceed with this entry";
$AA = $rec['totsb']-1;
$BB=$rec['sbstart'];
echo $AA;
$con=mysql_connect('localhost','root') or die ("Server connection failure!");
$db=mysql_select_db('regional_data',$con) or die ("Couldn't connect the database");
$SQL="UPDATE newchk SET totsb='$AA'";
return false;
}
}
else
{ echo "Error: Cant find choosen in the databse";
return false;
}
}
}
?>