Recently in the PHP course design, ask a question about extracting the form data into the database
Recently in the PHP course design, the most shopping site, I rookie, so the answer can be detailed point? Preferably with code, thank you.
This interface code is this:
$conn =mysql_connect (' localhost ', ' root ', ' 123 ') or Die (' Connection failed ');
mysql_select_db (' MySQL ', $conn) or Die (' Connection failed ');
mysql_query ("SET NAMES UTF8");
$sql = "SELECT * from goods";
$result =mysql_query ($sql);
echo "";
echo "";
echo " ";
echo "";
echo "";
echo "";
echo "";
echo "";
?>
-----------------------
What I want to ask is: how to put the tick option into the database, including the number.
Best can give code, thank you, I rookie Ah!!!
------Solution--------------------
Add a button value= "into the shopping cart" (it looks like you have a shot in it)
A checkbox traversing all checked states gets the name and number of the product through the checkbox's ID Association
The onclick triggers Ajax.
Backstage according to the ID to get the goods title,num storage.
------Solution--------------------
1. Change the name of your text to a group
Checkbook name to the array, value changed to the corresponding product ID
On the processing page
You can use $_get[' checkbox '] or $_post[' checkbox ' to get the selected item
foreach ($_post[' checkbox '] as $key = $id)
{
$_post[$key [' text '] is the number of goods $id
}
2. Use Ajax to spell the value of text into a string, such as: 1,1,2
So is the checkbox.
Finally Ajax commits, PHP does processing
------Solution--------------------
Switch
Then apply the code of # #
------Solution--------------------
foreach ($_post[' checkbox '] as $id)
{
$r =mysql_query ("SELECT * from goods where id= $id");
$rows = Mysql_fetch_row ($r);
mysql_query ("INSERT into goodsave values ($rows [0], ' $rows [1] ', ' $rows [2] ')");
}