none wrote:
Hi, when i use the following code;
$current_available = mysql_query("SELECT availableplaces FROM
tblCourses WHERE course_id='$_POST[selectedcourse]'");
$current_available -= 1;
mysql_query("UPDATE tblCourses SET
availableplaces='$current_available' WHERE
course_id='$_POST[selectedcourse]'");
I think I understand what you want, however you are doing it wrong.
Firstly you have an error, you need to fetch the result then decrement it.
$course_places = mysql_query("SELECT `availableplaces` - 1 FROM
`tblCourses` WHERE `course_id`='$_POST[selectedcourse]' LIMIT 1");
$amount_available = mysql_result($current_available, 0, 'availableplaces');
mysql_query("UPDATE `tblCourses` SET
`availableplaces`='$amount_available' WHERE
`course_id`='$_POST[selectedcourse]' LIMIT 1");
That should work, however there is a much faster, and easier way of
doing it (UNLESS YOU WANT THE AMOUNT AVAILABLE)!
mysql_query("UPDATE `tblCourses` SET
`availableplaces`=`availableplaces`-1 WHERE
`course_id`='$_POST[selectedcourse]' LIMIT 1");