New, the multi-line form as an array up into the database of a variety of small questions

Source: Internet
Author: User
Newcomers to help, the multi-line form as an array up into the database of a variety of small questions!
Because the needs of the site, need to do a page submission form, need to involve multi-line form as an array to submit to the database!
Degrees Niang Get an example:
























is to set each field to [] The itinerary array upload, the processing code is:
!--? php 
$db _name= "test";
$table _name= "Co_arr";
$connection = @mysql_connect ("localhost", "root", "smtroot") or Die (Mysql_error ());
$db = @mysql_select_db ($db _name, $connection) or Die (Mysql_error ());
mysql_query ("SET NAMES GBK");

Echo "
";  
Print_r ($_post["name"]);
Print_r ($_post["age"]);
Print_r ($_post["position"]);

//calculates the number of lines passed over the text box
$arr _length = count ($_post["name"]);

$name _arr = $_post["name"];
$age _arr = $_post["Age"];
$position _arr = $_post["position"];

/* Loop INSERT statement */
for ($i =0; $i < $arr _length; $i + +) {
$sql = "INSERT into Co_arr (name,age,position)";
$sql. = "VALUES (' $name _arr[$i] ', ' $age _arr[$i] ', ' $position _arr[$i] ')";
$query = @mysql_query ($sql, $connection) or Die (Mysql_error ());
//echo $_post["name" [$i]. "
";
}
?>
  • 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.