Jump to content

insert into database help


mishuk

Recommended Posts

Hi.  I am currently working on committing this to the database.  however my problem is that not all of these fields may be populated.  For example q3c may be left blank therefore only two records need committing to the db instead of three. 

 

What would a better way of doing this?  Would some sort of loop be best?

 

$workshop = ($_POST['q3a']);
$opinion =  ($_POST['q3a1']);

$addy10feedback = "INSERT INTO tbl_workshop_attended (stud_id, workshop_id, opinion_id)
    	  VALUES ('$stud', '$workshop', '$opinion')";

$result = mysql_query($addy10feedback) or die(mysql_error());

$workshop = ($_POST['q3b']);
$opinion =  ($_POST['q3b1']);

$addy10feedback = "INSERT INTO tbl_workshop_attended (stud_id, workshop_id, opinion_id)
   		       VALUES ('$stud', '$workshop', '$opinion')";

$result = mysql_query($addy10feedback) or die(mysql_error());

$workshop = ($_POST['q3c']);
$opinion =  ($_POST['q3c1']);

$addy10feedback = "INSERT INTO tbl_workshop_attended (stud_id, workshop_id, opinion_id)
	       VALUES ('$stud', '$workshop', '$opinion')";

$result = mysql_query($addy10feedback) or die(mysql_error());

Link to comment
https://forums.phpfreaks.com/topic/43242-insert-into-database-help/
Share on other sites

If a variable number or records may be added into the database (ie, 3 or 4 or 2 or 1 are all acceptable), I would recommend imploding all of the records together into one string and keeping them in one database field, then exploding them back into seperate records when you take them out of the database.

 

That's how my blogs handle tags, it works very well with variable amounts of input.

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.