Thanks for any help, I'm really quite frustrated!
Woaah, slow down Tiger.
Just ONE way to do this would be:
surveys table
id (autoincrement/tinyint/primary key)
survey_name (varchar)
max_respondants (int - stop collecting after certain amount)
active (tinyint - can switch off the survey manually)
form_html (text - place the 'cleaned' form html in here - just the inside 'guts' of the form - no form tags)
replies table
id (autoincrement/tinyint/primary key)
survey_id (foreign key on id in surveys table)
replies (text) - I'd use php functions serialize() and unserialize() to store the form $_POST variables as an array
Now this is a very basic setup, and somewhat complicates collating the data from the replies field due to the 'array' nature, but it's usable. I'm not using the active and max_respondants fields here, just for clarity.
At the top of your page, enter the code for finding the survey with the lowest number of respondants, something like:
<?php
$rs = mysql_query("SELECT surveys.id,surveys.form_html, COUNT(replies.survey_id) AS count1 FROM replies INNER JOIN surveys ON replies.survey_id = surveys.id GROUP BY replies.survey_id ORDER BY count1");
//get first record
$d = mysql_fetch_array($query);
//the "uncleaned" form html to display
$form_html = stripslashes(html_entity_decode($d['form_html']));
//the id of the form so the db knows which survey id to apply to the saved data
$id = $d['survey_id'];
?>
<form id=".." name="..." action="formhandler.php?id=" method="post">
<?php echo "<input type ='hidden' name='survey_id' id='survey_id' value='{$id}' />" . $form_html;?>
</form>
All your forms will be sent to the formhandler.php page, where all you do is send the data to the db (after 'cleaning' it).
For 'replies' table:
The $_POST['survey_id'] field will give the survey_id field
Next delete the $_POST['survey_id'] so it doesn't interfere with your $_POST array:
unset($_POST['survey_ id']);
The serialize($_POST) function should work to put the replies into a single field.
//EDIT//
Sorry G - went for a metaphysical walk during my reply.