Trying to Automate/Loop a Save Function
<p>EDIT: the difference between the pages are the simply $q1, $q2, $q3 becomes, for example, $q13, $q14, $q15 - they are questions in the form.</p>

<p>Hi all,</p>

<p>I have the following code:</p>

<pre><code>$rguid = $_POST["r"];
$ip=substr($_SERVER['REMOTE_ADDR'], 0, 50);
$browser=substr($_SERVER['HTTP_USER_AGENT'], 0, 255);   

$q1 = $_POST["q1"];
$q2 = $_POST["q2"];
$q3 = $_POST["q3"];
$q4 = $_POST["q4"];
$q5 = $_POST["q5"];
$q6 = $_POST["q6"];
$q7 = $_POST["q7"];
$q8 = $_POST["q8"];

$respondent_id = decode_respondent_guid($rguid);
$rcount=respondent_status($respondent_id);

if ($rcount==0) {

    $proc = mysqli_prepare($link, "INSERT INTO tresults (respondent_id, ip, browser, q1, q2, q3, q4, q5, q6, q7, q8) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
    mysqli_stmt_bind_param($proc, "issiiiiiiii", $respondent_id, $ip, $browser, $q1, $q2, $q3, $q4, $q5, $q6, $q7, $q8);
    mysqli_stmt_execute($proc);
    $mysql_error = mysqli_error($link);
    if ($mysql_error!="") {
        printf("Unexpected database error: %s\n", $mysql_error);
        mysqli_stmt_close($proc);
        mysqli_clean_connection($link);
        exit();
    } else
    {
        mysqli_stmt_close($proc);
        mysqli_clean_connection($link);
        update_completion_status($respondent_id, 'Started');
        header("Location: page2.php?r=".$rguid);
    }
}
</code></pre>

<p>This code works a treat - no problem.</p>

<p>At the moment, that code appears on a 'save' page that relates to a 'form' page (i.e. if I have 5 .php pages with a form on each, I need 5 save.php pages to save each pages data to the database) to save data to my SQL database.  What I would like is to have a single save.php page that will work with as many 'form' pages as I have.  So instead of manually having to setup and change each save page, it automates it.</p>

<p>I've no idea of the coding to do this, though I suspect something like a foreach or loop etc.</p>

<p>Any suggestions?</p>

<p>Thanks,</p>

<p>Homer.</p>
