|
Posted by plato on 10/13/63 11:27
Here's what I am trying to achieve:
I want to create a form which has a check box which adds entries to a
database e.g. value= course_1 and also on the form is a number denoting
places available e.g. value = places_1
e.g.
<check box> Course 1 (There are 11 places available)
each time a form with a course selected is submitted the next time the form
is accessed it reduces the places available by 1 until it reaches 0 when an
error message is returned.
I'm up to here:
<?PHP
//alter you variables here
$host = "localhost";
$username="";
$password="";
$database="paul";
// create link to database
$link = mysql_connect($host, $username, $password)
or die("Cannot connect to database");
mysql_select_db($database)
or die("Cannot select database");
//now we make the query which will ask the database for the course
information
//change the my_table to your course table name
$query = "SELECT* FROM test";
$result = mysql_query($query)
or die("Query cannot be executed");
//now we are going to print the information to your screen
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
printf ("course: %s places: %s<br>", $row['course'],
$row['places']);
}
?>
which gives me:
course: Course 1 places: 11
course: Course 2 places: 15
Now, if someone selects course 1 I want the places to reduce by 1 so the
next person who accesses the form will see places -1
thanks
plato
Navigation:
[Reply to this message]
|