Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Trying to store form input to Array

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Trying to store form input to Array

Postby reyes99 » Mon Jan 13, 2014 8:44 pm

Hi, I am trying to save form data to an array so I can display it in a table later. The problem I am having is that when I click the submit button and it reloads using php_self it seems to initialize the variables everytime. Here is an example of what I am trying to do.

Code: Select all
<?php

// if first time initialize variables
if (!isset($i)) {
   echo "in initialize section<br />";
   $i = 0;
   $itemno[] = "";
   $desc[] = "";
}

if (isset($_POST['submitbtn'])) {
   $itemno[$i] = $_POST['item'];
   $desc[$i]   = $_POST['desc'];

   echo "Item# = ".$itemno[$i]."<br />";
   echo "Desc. = ".$desc[$i]."<br />";

   $i += 1;
   echo "i = $i";
   var_dump($itemno);
   var_dump($desc);
}

?>

<form id="submititem" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="submit" >
   <input name="item" placeholder="Enter item #" size="18" />
   <input name="desc" placeholder="Enter Description" size="18" />
   <input name="submitbtn" type="submit" value=">">
</form>


Thanks

Ralph
reyes99
New php-forum User
New php-forum User
 
Posts: 2
Joined: Sat May 12, 2012 9:27 am

Re: Trying to store form input to Array

Postby gauravkachhadiya » Sat May 03, 2014 12:45 am

if you are upload multiple file then you can
<input type="file" name="file[]" id="file">
use and passed array on click submit buuton..
gauravkachhadiya
New php-forum User
New php-forum User
 
Posts: 5
Joined: Wed Apr 23, 2014 2:37 am


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.