Jump to content

mySQL logic...


Recommended Posts

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.";
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.