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
https://forums.phpfreaks.com/topic/204009-mysql-logic/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.