reportingsjr Posted August 17, 2006 Share Posted August 17, 2006 I have a system where you can select how many forms you want to create, and it uses a for statement to create all of these, then I need it so when they submit it, the forms get submitted into a mysql database 1 by 1, but since the naming system uses numbers, it wont work. how would I do this: for($i = "0"; $i < $_POST['amt']; $i++){ $query = "INSERT INTO `monsterdb` VALUES( '" . $_POST['{$i}name'] . "', '" . $_POST['{$i}level'] . "', '" . $_POST['{$i}members'] . "', '" . $_POST['{$i}habitat'] . "', '" . $_POST['{$i}exp'] . "', '" . $_POST['{$i}100%'] . "', '" . $_POST['{$i}gold'] . "', '" . $_POST['{$i}weapons'] . "', '" . $_POST['{$i}armour'] . "', '" . $_POST['{$i}other'] . "' )"; } How can I get this to work? I really need this because it will make my job like 100X easier . Link to comment Share on other sites More sharing options...
Jack McKalling Posted August 17, 2006 Share Posted August 17, 2006 Use this and see if it helps for($i = 0; $i < $_POST['amt']; $i++) { $query = "INSERT INTO `monsterdb` VALUES( '{$_POST["name{$i}"]}', '{$_POST["level{$i}"]}', '{$_POST["members{$i}"]}', '{$_POST["habitat{$i}"]}', '{$_POST["exp{$i}"]}', '{$_POST["100%{$i}"]}', '{$_POST["gold{$i}"]}', '{$_POST["weapons{$i}"]}', '{$_POST["armour{$i}"]}', '{$_POST["other{$i}"]}' )";} And change the names of the form elements so that the numbers follow the name instead of the other way round. Names starting with numbers may cause any problems Link to comment Share on other sites More sharing options...
reportingsjr Posted August 17, 2006 Author Share Posted August 17, 2006 Ohhh, double qoutes. thanks! Ill test it now :)But wouldnt the double qoutes interfere with the surrounding doubles? Maybe the curly brackets let them be there.. Link to comment Share on other sites More sharing options...
reportingsjr Posted August 17, 2006 Author Share Posted August 17, 2006 Thanks a ton!! It worked . Link to comment Share on other sites More sharing options...
Jack McKalling Posted August 17, 2006 Share Posted August 17, 2006 Indeed, if the string is dubble quoted, the quotes between the curly brackets don't matter what they are. They should at least be double too when inside those another pair of curly brackets will occur, like in this situation. 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