PMacca_1987 Posted April 17, 2010 Share Posted April 17, 2010 Hi everyone, Would somebody please try to help me with the problem I have below. Basically the fieldnames text box is being used as an array and the loop should populate it depending on the data entered into a number of text boxes, which changes each time (hence the loop). However, instead of giving me say 5 fields and storing each piece of data entered. It is giving me 5 fields and then storing each letter or number of the data entered in the last text box into the array individually and ignoring the input of the first boxes. I hope someone can help me out with this. Many Thanks in advance Paul <?php session_start(); function AddProduct2() { require "connect.php"; ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title></title> </head> <body> <form action="AddProduct.php" method="POST" name="AddProduct" > $result= mysql_query("SELECT * FROM ".$_SESSION['Username']."FieldNames"); if( !$result) exit('Error:<br />' . $query . '<br />' . mysql_error()); $i = mysql_num_rows($result); for($t=1; $t<=$i; $t++) { ?> <input name='FieldName[<?php echo $t?>]' type="text"><br> <?php }?> <input name="Save" type="image" src="images/add.png" align="right"> </form> </body> </html> <?php }?> Link to comment https://forums.phpfreaks.com/topic/198819-array-storing-each-letter-of-a-word-individually-not-collectively/ Share on other sites More sharing options...
khr2003 Posted April 22, 2010 Share Posted April 22, 2010 I am not sure what you are trying to achieve in your code. Are you trying to make input names as an array so when data is posted you will loop through them and insert them accordingly? if that is that is case then I believe all you have to do is to make the input filed name like this: <input name="FieldName[]" type="text" value="any value"> not the [] at the end of the name of the filed. this will convert the name into an array so when your data is posted you would have: FieldName0 FieldName1 FieldName2 .. etc hope this helps Link to comment https://forums.phpfreaks.com/topic/198819-array-storing-each-letter-of-a-word-individually-not-collectively/#findComment-1046211 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.