violinrocker Posted March 23, 2011 Share Posted March 23, 2011 im trying to do a multi insert form using for loop. the concept is specifying a number and then using it in the for loop. the loop then makes a number of fields depending on the specified number. after that i use another for loop to insert the grouped fields together. code for specifying desired number <? if ($_GET[num]=="") { ?><form name="form1" method="post" action="multiup.php?num=1"> <input name="num" type="text" value="10" maxlength="2"> <input type="submit" name="button" id="button" value="Submit"> </form><? } ?> <? } else { ?><form name="form2" method="post" action="multiup2.php"> <input name="adder" type="hidden" value=""> <input name="num" type="hidden" value="<? echo $_POST[num]; ?>"> code for displaying fields <? for ($i=1;$i<=$_POST[num];$i++) { echo "groupnumber<br /> <input name='eno$i' type='text' value='$i'> Thumb <input name='thumb$i' type='text'> link1<br /> ";} ?> the insert code <? if(isset($_POST['submit']) && ($_POST['submit'] == "Submit")) { $con = mysql_connect("lalalalala"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("kiphi_main", $con); for ($i=1;$i<=$_POST[num];$i++) { $title="$eno$i"; $sql="INSERT INTO articles (title) VALUES ('$_POST[$title]')"; } } if (!mysql_query($sql,$con)) {echo testest;}?> problem is i cant get it to work... should i try a different approach? Quote Link to comment https://forums.phpfreaks.com/topic/231492-help-with-multi-insert-using-for-loop/ Share on other sites More sharing options...
linus72982 Posted March 23, 2011 Share Posted March 23, 2011 You have a few errors here and there from first glance. You don't seem to have an ending bracket for the else stated in this line: <? } else { ?><form name="form2" method="post" action="multiup2.php"> You have one ending bracket on the second to last line of that section, but that ends the for loop in that section, not the else. Also, this line: {echo testest;}?> I'm not really sure what that's supposed to do but the way you have it written without the variable identifier ($), "testest" would need to be a constant. Did you mean $testest? That's just a first glance. If you are still having trouble, try to tell us what errors you are getting or maybe the incorrect output you are receiving, etc. It's hard to debug someone else's code when you don't know what's actually wrong with it. Quote Link to comment https://forums.phpfreaks.com/topic/231492-help-with-multi-insert-using-for-loop/#findComment-1191309 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.