morocco-iceberg Posted June 6, 2010 Share Posted June 6, 2010 Just having a bit of trouble with my logic. I'm not too sure how to go about doing this kind of thing. I have a form that first asks the user how many sections of data they want to enter. Then once that form is submitted depending on the number they input the relevant number of input boxes are shown for them to enter their data. This is where this code comes into play. When they submit the second form it activates this code, so for each field it inserts the data into the relevant slots. I have two problems: a) I need all the information inserted into the same row. b) If the correct number of fields do not yet exist in the table i need to create them and submit the relevant data. Here's what I've got so far, but I'm a little bit stuck... if(isset($_POST["add"])){ $section = "sent"; $level = $_POST["level"]; $table = $section . $level; $number = $_POST["number"]; $i = 0; while($i<$number){ $i = mysql_real_escape_string($_POST["$i"]); mysql_query("INSERT INTO $table ('$i') VALUES ('$i')") or die($error_message); $i++; } $success_message = "Question was added."; } Quote Link to comment Share on other sites More sharing options...
Mchl Posted June 6, 2010 Share Posted June 6, 2010 a) I need all the information inserted into the same row. b) If the correct number of fields do not yet exist in the table i need to create them and submit the relevant data. I suggest you rethink your database design. Quote Link to comment Share on other sites More sharing options...
morocco-iceberg Posted June 6, 2010 Author Share Posted June 6, 2010 Haha, will do, still only learning these things. Quote Link to comment 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.