hossfly007 Posted November 16, 2007 Share Posted November 16, 2007 I am trying to create a loop to insert data into my database and i am needing alittle help: $players = "{$_POST['players']}"; $j=1; while($j<=$players) { $query = "INSERT INTO sl_data VALUES ( '0', '{$_POST['name$j']}', '{$_POST['date$j']}', '{$_POST['rank$j']}', '{$_POST['oscore$j']}', '{$_POST['nscore$j']}', '{$_POST['ohand$j']}', '{$_POST['nhand$j']}', '{$_POST['points$j']}',)"; $j++; $text .= "$query"; } The issue i am having is the $j will not show up as a number when i load the page. it just shows this: INSERT INTO sl_data VALUES ( '0', '', '', '', '', '', '', '', '', ) INSERT INTO sl_data VALUES ( '0', '', '', '', '', '', '', '', '', ) I am thinking that {$_POST['name$j']} will not work. But i have no idea how to put a variable in a variable. Any ideas? Thanks for the help!! Just for reference here is my form: $text .= "<form action='sl_submit.php?action=step3' method='post'>"; $players = "{$_POST['players']}"; $i=1; while($i<=$players) { $text .= " <tr> <td><input type='text' name='rank$i' size='20' class='tbox'></td> <td><input type='text' name='name$i' size='20' class='tbox'></td> <td><input type='text' name='ohand$i' size='20' class='tbox'></td> <td><input type='text' name='oscore$i' size='20' class='tbox'></td> <td><input type='text' name='nhand$i' size='20' class='tbox'></td> <td><input type='text' name='nscore$i' size='20' class='tbox'></td> <td><input type='text' name='points$i' size='20' class='tbox'></td> </tr>"; $i++; } $text .= " <tr><td> <input type='hidden' name='players' value='{$_POST['players']}'> <input type='hidden' name='date' value='{$_POST['date']}'> <input type='hidden' name='location' value='{$_POST['location']}'> <input type='submit' value='Submit' class='tbox'></td></tr></table></form>"; Quote Link to comment https://forums.phpfreaks.com/topic/77669-solved-query-post-help/ Share on other sites More sharing options...
only one Posted November 16, 2007 Share Posted November 16, 2007 What are you trying to do with $_POST['name$j']? Maybe you were trying to do $_POST['name'] .= $j; Quote Link to comment https://forums.phpfreaks.com/topic/77669-solved-query-post-help/#findComment-393198 Share on other sites More sharing options...
hossfly007 Posted November 16, 2007 Author Share Posted November 16, 2007 I am trying to add information into a database without adding the information one at a time. Ex. - This is being used for a singles league, Where you have to input the rank, players name, handicap, old handicap, score, adjusted score, points. If 20 players come one day that's 20 single queries i would have to do. I am trying to just do all of it at one time. Create a form (the while statement) to create as many inputs as there are players. and then submit all of the information in one loop. Quote Link to comment https://forums.phpfreaks.com/topic/77669-solved-query-post-help/#findComment-393199 Share on other sites More sharing options...
hossfly007 Posted November 16, 2007 Author Share Posted November 16, 2007 also, i have the inputs named as rank1, rank2, rank3, rank4 and so on. So all i have to do is find a way to make the {"$_POST['rank']} go up in order aswell: {"$_POST['rank1']}, {"$_POST['rank2']}, {"$_POST['rank3']}, {"$_POST['rank4']}. the number escalating is the $j Quote Link to comment https://forums.phpfreaks.com/topic/77669-solved-query-post-help/#findComment-393201 Share on other sites More sharing options...
hossfly007 Posted November 16, 2007 Author Share Posted November 16, 2007 i have found the problem, instead of: '{$_POST['name$j']}' it would be: '{$_POST["name$j"]}' Quote Link to comment https://forums.phpfreaks.com/topic/77669-solved-query-post-help/#findComment-393209 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.