Basically I have a Table on a php web page with an update checkbox which will update 1 of the database fields. The data needed to be updated is the available field. I want the available field to increment from its current count by one. For example if the database shows my table witch a row with available of 5 when it gets
checkboxed and the update button is pressed it displays in the same table after the refresh as 6. I have code for what i am trying to do but i am not sure of where i am going wrong with the query.
GET CHECKBOXES
$Update = $_GET['Update'];
GET EXISTING RECORDS
$ID = $GET['ID'];
$CARNAME = $GET['CARNAME'];
$FUELTYPE = $GET['FUELTYPE'];
$TRANSMISSION = $GET['TRANSMISSION'];
$ENGINESIZE = $GET['ENGINESIZE'];
$DOORS = $GET ['DOORS'];
$TOTAL = $GET ['TOTAL'];
$AVAILABLE = $GET ['AVAILABLE'];
CONNECT TO DATABASE
$link = mysql_connect ("hhhhhhh", "uuuuuuu", "pppppp");
mysql_select_db ("dbdbdbdbdbd");
UPDATE AVAILABLE BY ONE ----- THIS IS THE PART WHERE I AM TRYING TO GET THE UPDATE WORKING BUT I REALLY DONT KNOW WHAT TO DO......
if ($update [$i] == "update")
$query = "SELECT * FROM XYZ WHERE ID='$ID'";
mysql_query("UPDATE XYZ SET AVAILABLE = AVAILABLE -1 WHERE ID = '".$ID."'");
echo mysql_error();
RELOAD DATABASE AFTER MODIFICATIONS
$query = "SELECT * from XYZ";
$result = mysql_query ($query);
UPDATED TABLE TO BE DISPLAYED
print ("<form action=*********** method=\"get\">");
print ("<table border='1'>");
print ("<tr><th>Car Name</th><th>Fuel Type</th><th>Transmission</th><th>Engine Size</th><th>Doors</th><th>Total</th><th>Available</th><th>Date Added</th><th colspan='2'></th></tr>");
print ("<td><input type=\"text\" name=\"CARNAME\" size=20></td>");
print ("<td><input type=\"text\" name=\"FUELTYPE\" size=20></td>");
print ("<td><input type=\"text\" name=\"TRANSMISSION\" size=20></td>");
print ("<td><input type=\"text\" name=\"ENGINESIZE\" size=20></td>");
print ("<td><input type=\"text\" name=\"DOORS\" size=15></td>");
print ("<td><input type=\"text\" name=\"TOTAL\" size=15></td>");
print ("<td><input type=\"text\" name=\"AVAILABLE\" size=20></td>");
for ($i = 0; $i < mysql_num_rows ($result); $i ++)
{
$row = mysql_fetch_object ($result);
print ("<tr>");
printf ("<td><input type='text' name='CARNAME[$i]' value='%s' size='20'></td>", $row->CARNAME);
printf ("<td><input type='text' name='FUELTYPE[$i]' value='%s' size='20'></td>", $row->FUELTYPE);
printf ("<td><input type='text' name='TRANSMISSION[$i]' value='%s' size='20'></td>", $row->TRANSMISSION);
printf ("<td><input type='text' name='ENGINESIZE[$i]' value='%s' size='20'></td>", $row->ENGINESIZE);
printf ("<td><input type='text' name='DOORS[$i]' value='%s' size='15'></td>", $row->DOORS);
printf ("<td><input type='text' name='TOTAL[$i]' value='%s' size='15'></td>", $row->TOTAL);
printf ("<td><input type='text' name='AVAILABLE[$i]' value='%s' size='20'></td>", $row->AVAILABLE);
printf ("<input type='hidden' name='ID[$i]' value='%d' size='20'>", $row->ID);
printf ("<td>Update <input type='checkbox' name='update[$i]' value='update'></td>");
print ("</tr>");
}
printf ("<tr><td colspan='6' align='center'><input type=\"submit\" value=\"Update Database\"></td></tr></table></form>");
mysql_close ($link);[/code]
please tell me where i am going wrong?
I have tried numerous queries but i am not exactly a pro programmer. I have done X amount of research and can not really figure out how to do this??????
THANKS!!