mishuk Posted March 18, 2007 Share Posted March 18, 2007 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 More sharing options...
chawezul Posted March 18, 2007 Share Posted March 18, 2007 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. Link to comment https://forums.phpfreaks.com/topic/43242-insert-into-database-help/#findComment-209967 Share on other sites More sharing options...
mishuk Posted March 18, 2007 Author Share Posted March 18, 2007 cool cheers. Would that work ok when querying it. Link to comment https://forums.phpfreaks.com/topic/43242-insert-into-database-help/#findComment-209971 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.