mysqli_stmt_bind_param($proc, "iss$is", $respondent_id, $ip, $browser, $qStr1);
It's just this that is causing the problem, even though $qStr1 contains the text $q1, $q2 etc. as things stand I think $qStr1 is being treated as a single variable within the code, I guess I need to extract the text and then use it but no sure how?
Using the answer provided below, I have modified and added to:
$qStr = '';
$markStr = '';
for($i=1; $i<11; $i++)
{
$qStr .= 'q'.$i.'';
$qStr1 .= '$q'.$i.'';
$markStr .= '?';
$is .= 'i';
if($i < 10)
{
$qStr .= ', ';
$qStr1 .= ', ';
$markStr .= ', ';
}
}
$proc = mysqli_prepare($link, "INSERT INTO tresults (respondent_id, ip, browser, $qStr) VALUES (?, ?, ?, $markStr);");
mysqli_stmt_bind_param($proc, "iss$is", $respondent_id, $ip, $browser, $qStr1);
Now, I'm having a problem with $qStr1 - even though this is looping through and providing the correct output $q1, $q2 etc. - it's not saving to the DB, if I manually place $q1, $q2, etc in the mysqli_stmt_bind_param and leave the rest using the loop it works correctly.
I have the following code:
$proc = mysqli_prepare($link, "INSERT INTO tresults (respondent_id, ip, browser, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
mysqli_stmt_bind_param($proc, "issiiiiiiiiii", $respondent_id, $ip, $browser, $q1, $q2, $q3, $q4, $q5, $q6, $q7, $q8, $q9, $q10);
mysqli_stmt_execute($proc);
What I am trying to achieve is a loop (at least I think it is) that will place the q1, q2, q3, q4, q5 etc. automatically into that code and also place the correct numbers of ? in there are well.
Is the question clear and can anyone assist?
q+number, or …? And what have your tried so far?