Recently, I was designing a PHP course and asked a question about how to store the extracted form data into a database.

Source: Internet
Author: User
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]')");
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.