Recently in the PHP course design, ask a question about extracting the data from the form into the database

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

    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.