WesleyA Posted June 4, 2015 Share Posted June 4, 2015 The idea is to insert with the browser a multiple input field, a loop, into mysql database. Is the solution to first put this loop input variable in an array and after that create in this case multible tables? Or is an array not necessary? Link to comment Share on other sites More sharing options...
justsomeguy Posted June 4, 2015 Share Posted June 4, 2015 Arrays are never really necessary, they just make it easier to deal with related data. Without an array you couldn't really use a loop, for example. If you want to do that in a loop then use an array. Link to comment Share on other sites More sharing options...
WesleyA Posted June 5, 2015 Author Share Posted June 5, 2015 If its easier and you need it for a loop then I go fo the array. I'm stuck with the following script. <?php echo "<form method = 'POST' target = '_blank'>"; for($x = 0; $x < 5; $x++) { echo "<input type = 'text' name = 'runame' /></br>"; } echo "<input type = 'submit' value = 'send' /> "; echo "</from>"; //// if (isset($_POST['runame'])) { $runame = $_POST['runame']; for($x = 0; $x < 5; $x++){ $test[$x] = array($runame => $x); } } if (isset ($test)) { echo "<pre>"; for($x = 0; $x < 5; $x++){ print_r($test[$x]); } echo "</pre>"; } ?> Only the last entry is taken. I also want the first four entries. Link to comment Share on other sites More sharing options...
dsonesuk Posted June 5, 2015 Share Posted June 5, 2015 For name attribute use name='runame[]', you are just overwriting the previous using name attribute value with current value. Link to comment Share on other sites More sharing options...
WesleyA Posted June 5, 2015 Author Share Posted June 5, 2015 (edited) yeah I was figuring out something in that direction, but just adding [] to runame is not possible, in array it gives a fatal error report due to []. Edited June 5, 2015 by WesleyA Link to comment Share on other sites More sharing options...
dsonesuk Posted June 5, 2015 Share Posted June 5, 2015 You are placing an array within array, try $runame[$x] instead of array($runame => $x). Link to comment Share on other sites More sharing options...
dsonesuk Posted June 5, 2015 Share Posted June 5, 2015 You don't need for loop for print_r You can have array within array as you original wanted with <?php echo "<form method = 'POST' target = '_blank'>"; for ($x = 0; $x < 5; $x++) { echo "<input type = 'text' name = 'runame[]' value='aaaa" . $x . "' /></br>"; } echo "<input type = 'submit' value = 'send' /> "; echo "</from>"; if (isset($_POST['runame'])) { $runame = $_POST['runame']; for ($x = 0; $x < 5; $x++) { $test[$x] = array($runame[$x]); } } if (isset($test)) { echo "<pre>"; //for ($x = 0; $x < 5; $x++) { print_r($test); // } echo "</pre>"; } ?> or one single array, but you would get same result just with print_r($runame); without adding to another array that is storing the same values. <body> <?php echo "<form method = 'POST' target = '_blank'>"; for ($x = 0; $x < 5; $x++) { echo "<input type = 'text' name = 'runame[]' value='aaaa" . $x . "' /></br>"; } echo "<input type = 'submit' value = 'send' /> "; echo "</from>"; if (isset($_POST['runame'])) { $runame = $_POST['runame']; for ($x = 0; $x < 5; $x++) { $test[$x] = $runame[$x]; } } if (isset($test)) { echo "<pre>"; //for ($x = 0; $x < 5; $x++) { print_r($test); // } echo "</pre>"; } ?> Link to comment Share on other sites More sharing options...
WesleyA Posted June 6, 2015 Author Share Posted June 6, 2015 Is it one way or another possible to put php code inside a html input tag? I was looking for a html tag to identify exactly how an input variable should have an index. Link to comment Share on other sites More sharing options...
dsonesuk Posted June 6, 2015 Share Posted June 6, 2015 I don't understand? Give example. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now