variables - PHP For loop required for storing data in MySQL -


mysqli_stmt_bind_param($proc, "iss$is", $respondent_id, $ip, $browser, $qstr1); 

it's causing problem, though $qstr1 contains text $q1, $q2 etc. things stand think $qstr1 being treated single variable within code, guess need extract text , use no sure how?

using answer provided below, have modified , 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 tresults (respondent_id, ip, browser, $qstr) values (?, ?, ?, $markstr);"); mysqli_stmt_bind_param($proc, "iss$is", $respondent_id, $ip, $browser, $qstr1); 

now, i'm having problem $qstr1 - though looping through , providing correct output $q1, $q2 etc. - it's not saving db, if manually place $q1, $q2, etc in mysqli_stmt_bind_param , leave rest using loop works correctly.

i have following code:

$proc = mysqli_prepare($link, "insert 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 trying achieve loop (at least think is) place q1, q2, q3, q4, q5 etc. automatically code , place correct numbers of ? in there well.

is question clear , can assist?

try

<?php     $qstr = '';     $markstr = '';      for($i=1; $i<11; $i++)     {         $qstr .= 'q'.$i.'';         $markstr .= '?';         if($i < 10)         {             $qstr .= ', ';             $markstr .= ', ';         }     }       $proc = mysqli_prepare($link, "insert tresults (respondent_id, ip, browser, $qstr) values (?, ?, ?, $markstr);"); ?> 

the output of $qstr & $markstr

$qstr = q1,q2,q3,q4,q5,q6,q7,q8,q9,q10 $markstr = ?,?,?,?,?,?,?,?,?,? 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -