PHP Implementation Click the Add button to add a single line of items and insert all the contents into the database

Source: Internet
Author: User

PHP Implementation Click the Add button to add a single line of items and insert all the contents into the database

:

Html+jquery:

<HTML>  <Head>  <Metahttp-equiv= "Content-type"content= "Text/html;charset=utf-8">  <Scriptlanguage= "JavaScript"type= "Text/javascript"src= "Jquery.min.js"></Script>  <Scripttype= "Text/javascript">  $(function(){      $(': Button[name=add]'). Click (function() {inserttr (); })      $('Button[name=del]'). Click (function(){          $( This). Parents ('TR'). Remove (); })      $(': Button[name=delall]'). Click (function(){          $('. Itme'). Remove (); })  })  varGradei=1; functioninserttr () {varHTML="'; HTML+='<tr class= "Itme" ><td><input type= "text" Name= "data[time][]" ></td>'; HTML+='<td><input type= "Radio" name= "data[grade]['+Gradei+'] "value=" 1 "> Good <input type=" Radio "name=" data[grade]['+Gradei+'] "value=" 2 "> Very good </td>'; HTML+='<td><select name= "data[type][" ><option value= "excellent student" > excellent student </option><option value= "again honoured "> Again honoured </option></select></td>'; HTML+='<td><button name= "del" > Delete </button></td></tr>'; $('#tab'). append (HTML); $('Button[name=del]'). Click (function(){          $( This). Parents ('TR'). Remove (); }) Gradei++; }  </Script>  </Head>  <Body>     <formAction= "exe.php"Method= "POST"name= "F1">      <Tablewidth= "500px"ID= "tab">          <TR><th>Date</th><th>Level</th><th>Kinds</th><th>Operation</th></TR>          <TRclass= "Itme">              <TD><inputtype= "text"name= "data[time][]"></TD>              <TD><inputtype= "Radio"name= "Data[grade][0]"value= "1">Good<inputtype= "Radio"name= "Data[grade][0]"value= "2">Very good</TD>              <TD><Selectname= "data[type][]"><optionvalue= "Excellent student">Excellent student</option><optionvalue= "Again honoured">Again honoured</option></Select></TD>              <TD><Buttonname= "Del">Delete</Button></TD>          </TR>      </Table>      <Div><inputtype= "Submit"name= "Sub"value= "Save" /><inputtype= "button"name= "Delall"value= "Delete all"><inputtype= "button"name= "Add"value= "Add"></Div>  </form>     </Body>  </HTML>  

exe.php

<? php     $arr _time=$_post[' data ' [' time '];  $arr _grade=$_post[' data ' [' Grade '];  $arr _type=$_post[' data ' [' type '];     for ($i =0; $i <count ($arr _time); $i + +) {      $insert [$i] [' Time ']= $arr _time[$i];      $insert [$i] [' Grade ']= $arr _grade[$i];      $insert [$i] [' type ']= $arr _type[$i];  }     echo "<pre>";  Print_r ($insert);  echo "</pre>";  /* Each data is a data array (     [0] = = Array         ([time] + =             November 7, 2014 15:50:18             [grade] + 1             [Type] = > Again honoured         )       [1] = = Array         (             [TIME] = November 7, 2014 15:50:24             [Grade]             = 2 [Type] = > Excellent student         )       [2] = = Array         (             [TIME] = November 7, 2014 15:50:27             [Grade] = 1             [Type] = > Again honoured         )   ) *  /?>  

PHP Implementation Click the Add button to add a single line of items and insert all the contents into the database

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.