Recently, I am working on PHP course design and asked a question about saving the extracted form data to the database. Recently, I am working on PHP course design, the most shopping website, I am a newbie, so can I give a detailed answer? It is best to include code. thank you. The interface code is as follows: & lt ;? Php $ conn = mysql_connect ('localhost', 'root', '000000') or & nb recently designed a PHP course and asked a question about saving extracted form data to the database.
Recently, I am working on PHP course design, the most shopping website, and I am a newbie. can I give a detailed answer? It is best to include code. thank you.
The interface code is as follows:
$ Conn = mysql_connect ('localhost', 'root', '000000') 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 checked options into the database, including the quantity.
It is best to provide code. thank you, Cainiao !!!
------ Solution --------------------
Add another button value = "Add to shopping cart" (It seems that you have one in your call)
Traverses all checked status checkboxes and obtains the product name and quantity through the id association of the checkbox.
Trigger ajax in onclick
The background obtains the title and num of the item according to the id.
------ Solution --------------------
1. change your text name to an array.
Change the checkbook name to an array and the value to the corresponding item id.
On the processing page
You can use $ _ GET ['checkbox'] or $ _ POST ['checkbox'] to obtain the selected item.
Foreach ($ _ POST ['checkbox'] as $ key => $ id)
{
$ _ POST [$ key] ['text'] indicates the quantity of the product $ id.
}
2. use ajax to splice the text value into a string, for example, 2.
The same is true for checkbox.
Final ajax submission, php processing
------ Solution --------------------
Change
Then apply the #2 code
------ 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]')");
}