Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    posting array in php

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <script language="javascript">
    row_no=0;
    function addRow(tbl,row){
    row_no++;


    var textbox = row_no+'. )<input type="text" size = "2" maxlength= "4" name= Id[]>';
    var textbox2 = '<input type="text" size = "20" maxlength= "50" name= Name[]>';
    var textbox3 = '<input type="text" size = "2" maxlength= "20" name= Date1[]>';
    var textbox4 = '<input type="text" size = "2" maxlength= "20" name= Date2[]>';
    var textbox5 = '<input type="text" size = "2" maxlength= "20" name= Date3[]>';
    var textbox6 = '<input type="text" size = "2" maxlength= "20" name= Date4[]>';
    var textbox7 = '<input type="text" size = "2" maxlength= "20" name= Date5[]>';
    var textbox8 = '<input type="text" size = "2" maxlength= "20" name= Date6[]>';
    var textbox9 = '<input type="text" size = "2" maxlength= "20" name= Date7[]>';
    var textbox10= '<input type="text" size = "2" maxlength= "20" name= Date8[]>';
    var textbox11= '<input type="text" size = "2" maxlength= "20" name= Date9[]>';
    var textbox12= '<input type="text" size = "2" maxlength= "20" name= Date10[]>';
    var textbox13= '<input type="text" size = "2" maxlength= "20" name= Date11[]>';
    var textbox14= '<input type="text" size = "2" maxlength= "20" name= Date12[]>';
    var textbox15= '<input type="text" size = "2" maxlength= "20" name= Date13[]>';
    var textbox16= '<input type="text" size = "2" maxlength= "20" name= Date14[]>';
    var textbox17= '<input type="text" size = "2" maxlength= "20" name= Date15[]>';
    var textbox18= '<input type="text" size = "2" maxlength= "20" name= Date16[]>';
    var textbox19= '<input type="text" size = "2" maxlength= "20" name= Date17[]>';
    var textbox20= '<input type="text" size = "2" maxlength= "20" name= Date18[]>';
    var textbox21= '<input type="text" size = "2" maxlength= "20" name= Date19[]>';
    var textbox22= '<input type="text" size = "2" maxlength= "20" name= Date20[]>';
    var textbox23= '<input type="text" size = "2" maxlength= "20" name= Date21[]>';
    var textbox24= '<input type="text" size = "2" maxlength= "20" name= Date22[]>';
    var textbox25= '<input type="text" size = "2" maxlength= "20" name= Date23[]>';
    var textbox26= '<input type="text" size = "2" maxlength= "20" name= Date24[]>';
    var textbox27= '<input type="text" size = "2" maxlength= "20" name= Date25[]>';
    var textbox28= '<input type="text" size = "2" maxlength= "20" name= Date26[]>';
    var textbox29= '<input type="text" size = "2" maxlength= "20" name= Date27[]>';
    var textbox30= '<input type="text" size = "2" maxlength= "20" name= Date28[]>';
    var textbox31= '<input type="text" size = "2" maxlength= "20" name= Date29[]>';
    var textbox32= '<input type="text" size = "2" maxlength= "20" name= Date30[]>';
    var textbox33= '<input type="text" size = "2" maxlength= "20" name= Date31[]>';
    var tbl = document.getElementById(tbl);
    var rowIndex = document.getElementById(row).value;
    var newRow = tbl.insertRow(row_no);
    var newCell = newRow.insertCell(0);
    newCell.innerHTML = textbox;
    var newCell = newRow.insertCell(1);
    newCell.innerHTML = textbox2;
    var newCell = newRow.insertCell(2);
    newCell.innerHTML = textbox3;
    var newCell = newRow.insertCell(3);
    newCell.innerHTML = textbox4;
    var newCell = newRow.insertCell(4);
    newCell.innerHTML = textbox5;
    var newCell = newRow.insertCell(5);
    newCell.innerHTML = textbox6;
    var newCell = newRow.insertCell(6);
    newCell.innerHTML = textbox7;
    var newCell = newRow.insertCell(7);
    newCell.innerHTML = textbox8;
    var newCell = newRow.insertCell(8);
    newCell.innerHTML = textbox9;
    var newCell = newRow.insertCell(9);
    newCell.innerHTML = textbox10;
    var newCell = newRow.insertCell(10);
    newCell.innerHTML = textbox11;
    var newCell = newRow.insertCell(11);
    newCell.innerHTML = textbox12;
    var newCell = newRow.insertCell(12);
    newCell.innerHTML = textbox13;
    var newCell = newRow.insertCell(13);
    newCell.innerHTML = textbox14;
    var newCell = newRow.insertCell(14);
    newCell.innerHTML = textbox15;
    var newCell = newRow.insertCell(15);
    newCell.innerHTML = textbox16;
    var newCell = newRow.insertCell(16);
    newCell.innerHTML = textbox17;
    var newCell = newRow.insertCell(17);
    newCell.innerHTML = textbox18;
    var newCell = newRow.insertCell(18);
    newCell.innerHTML = textbox19;
    var newCell = newRow.insertCell(19);
    newCell.innerHTML = textbox20;
    var newCell = newRow.insertCell(20);
    newCell.innerHTML = textbox21;
    var newCell = newRow.insertCell(21);
    newCell.innerHTML = textbox22;
    var newCell = newRow.insertCell(22);
    newCell.innerHTML = textbox23;
    var newCell = newRow.insertCell(23);
    newCell.innerHTML = textbox24;
    var newCell = newRow.insertCell(24);
    newCell.innerHTML = textbox25;
    var newCell = newRow.insertCell(25);
    newCell.innerHTML = textbox26;
    var newCell = newRow.insertCell(26);
    newCell.innerHTML = textbox27;
    var newCell = newRow.insertCell(27);
    newCell.innerHTML = textbox28;
    var newCell = newRow.insertCell(28);
    newCell.innerHTML = textbox29;
    var newCell = newRow.insertCell(29);
    newCell.innerHTML = textbox30;
    var newCell = newRow.insertCell(30);
    newCell.innerHTML = textbox31;
    var newCell = newRow.insertCell(31);
    newCell.innerHTML = textbox32;
    var newCell = newRow.insertCell(32);
    newCell.innerHTML = textbox33;
    }
    </script>
    </head>

    <body>
    <?php
    if(!isset($_POST['submit']))
    {
    ?>
    <form name="form1" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
    Standard
    <input type="text" name="textfield" />
    Section
    <input type="text" name="textfield2" />
    Month
    <input type="text" name="textfield3" />
    Year
    <input type="text" name="textfield4" />
    <p>
    <button onClick="addRow('table1','row1');">
    Add Row</button></p>

    <table width="100" border="1" cellspacing="0" cellpadding="2" id="table1">
    <th>ID</th>
    <th>NAME</th>
    <th>1</th>
    <th>2</th>
    <th>3</th>
    <th>4</th>
    <th>5</th>
    <th>6</th>
    <th>7</th>
    <th>8</th>
    <th>9</th>
    <th>10</th>
    <th>11</th>
    <th>12</th>
    <th>13</th>
    <th>14</th>
    <th>15</th>
    <th>16</th>
    <th>17</th>
    <th>18</th>
    <th>19</th>
    <th>20</th>
    <th>21</th>
    <th>22</th>
    <th>23</th>
    <th>24</th>
    <th>25</th>
    <th>26</th>
    <th>27</th>
    <th>28</th>
    <th>29</th>
    <th>30</th>
    <th>31</th>
    <tr id="row1">
    </tr>
    </table>
    <p>
    <input type="submit" name="submit" value="Submit" />
    </p>
    </form>
    <p>
    <?php
    }
    else
    {
    $connection=mysql_connect("localhost","root","")or die("unable to connect");
    $db="login";
    $db_select=mysql_select_db($db) or die("unable");
    $Standard=empty($_POST['textfield']) ? die ("ERROR:Enter your Id"):mysql_escape_string($_POST['textfield']);
    $Section=empty($_POST['textfield2']) ? die ("ERROR:Enter your textfield"):mysql_escape_string($_POST['textfield2']);
    $Month=empty($_POST['textfield3']) ? die ("ERROR:Enter your Id"):mysql_escape_string($_POST['textfield3']);
    $Year=empty($_POST['textfield4']) ? die ("ERROR:Enter your textfield"):mysql_escape_string($_POST['textfield4']);
    $Id[]=empty($_POST['Id']) ? die ("ERROR:Enter your Id1"):mysql_escape_string($_POST['Id']);
    $Name[]=empty($_POST['Name']) ? die ("ERROR:Enter your Name"):mysql_escape_string($_POST['Name']);

    $query="INSERT INTO attendance1 (Standard,Section,Month,Year,Id,Name) VALUES ('$Standard','$Section','$Month','$Year','$Id','$Name')";
    $result=mysql_query($query)or die("Error in query:$query. ".mysql_error());
    echo success;
    }
    ?>
    </p>
    </body>
    </html>


    Here in this coding i can insert values in text box,but it is inserted into mysql database

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Moving from PHP Snippets to PHP forum.
    Also, please wrap code with [code][/code] or [php][/php] code tags so its easily readable.
    These lines add the value of the given fields as items in the array, not as the array:
    PHP Code:
    $Id[]=empty($_POST['Id']) ? die ("ERROR:Enter your Id1"):mysql_escape_string($_POST['Id']);
    $Name[]=empty($_POST['Name']) ? die ("ERROR:Enter your Name"):mysql_escape_string($_POST['Name']); 
    $Id and $Name are now an array with a single item representing an array of the fields. Drop the brackets off of the php variable declaration and than serialize them if you want to use them in that query. You should normalize you're database though, otherwise you're going to end up with some substantial anomalies in the future.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •