|
Posted by Sander on 10/10/66 11:27
> <?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");
> print("Debug: $course<br>");
>
> //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['course'],$row['course'],$row['places']);
> }
> print("</SELECTED>\n");
> print("<INPUT name='submit' type='submit'>\n");
> print("</FORM>\n");
> ?>
> The result:
> Debug: Course 1
> Update cannot be executed
>
> Not sure what is wrong... don't know why the db won't update. Any ideas I
> can try/check?
>
> thanks
>
> plato
>
>
Dude,
I told you before. You copied and pasted my code directly but it has
different fieldnames in the MySQL than you have in you MySQL.
Here look at this 2 sentences:
1. $result = mysql_query("update test set places=places-1 where
number='$course'")
2. printf("<OPTION value='%s'> %s (%s places available)</OPTION>\n",
$row['course'],$row['course'],$row['places']);
Line 1:
You want to update your table named test and lowers the value places in the
database with 1. The update criteria is after the "where" in this line and
it says that php has to perform this action only if in your database there
is a record called number and it has a value of posted in $course. I bet you
have to rename the word " number" to "course".
Line 2:
In line 2 you can see that you read the records course and places. So if
that is giving you any output change the word "number" in the update
statement to "course"
Sander
Navigation:
[Reply to this message]
|