|
Posted by plato on 10/13/67 11:27
"Sander" <swuste zit bij cartel.nl> wrote in message
news:4332ad77$0$16947$ba620dc5@text.nova.planet.nl...
> > 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
> >
> >
>
> I had some time left so here is the thing you want, maybe you have to
change
> some variable names etc etc but i tested it and it works:
>
>
>
> <?PHP
>
> //alter you variables here
> //alter you variables here
> $host = "localhost";
> $username="";
> $password="";
> $database="paul";
>
> $submit = $_POST['submit'];
> $course = $_POST['course'];
>
> //
> $link = mysql_connect($host, $username, $password)
> or die("Cannot connect to database");
>
> mysql_select_db($database)
> or die("Cannot select database");
>
> //check if we can update the database
> if($submit)
> {
> $result = mysql_query("update test set places=places-1 where
> number='$course'")
> or die("Update cannot be executed");
>
> print("Changed database<br>");
> }
>
>
> //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");
>
> print("<FORM method=post>\n");
> print("<SELECT name=course>\n");
> //now we are going to print the information to your screen
> while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
> printf("<OPTION value='%s'> %s (%s places available)</OPTION>\n",
> $row['number'],$row['number'],$row['places']);
> }
> print("</SELECTED>\n");
> print("<INPUT name='submit' type='submit'>\n");
> print("</FORM>\n");
> ?>
>
>
> Sander Swuste
>
Reasons the database won't update might be? (Places is set as an integer)
plato
Navigation:
[Reply to this message]
|