Reply to Re: Decrementing a number...

Your name:

Reply:


Posted by Sander on 10/13/79 11:27

> 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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация