php - Inserting multiple row records using mysqli bind_param? -
i have code here works using mysql query.
$n = count($fullname); for($i=0; $i < $n; $i++) mysql_query("insert famcomp(fullname,fage,frel,fcivil,fedu,foccup,finco,app_id) values ('$fullname[$i]','$fage[$i]','$frel[$i]','$fcivil[$i]','$fedu[$i]','$foccup[$i]','$finco[$i]','$id')");
how convert mysqli bind_param
here's did: (i have connection.php
(mysqli
))
$n = count($fullname); for($i=0; $i < $n; $i++) $stmt = $conn->prepare("insert famcomp(fullname,fage,frel,fcivil,fedu,foccup,finco,app_id) values (?,?,?,?,?,?,?,?)"); $stmt ->bind_param("ssssssss",$fullname[$i],$fage[$i],$frel[$i],$fcivil[$i],$fedu[$i],$foccup[$i],$finco[$i],$id); }
but still not getting data.
with code:
$n = count($fullname); for($i=0; $i < $n; $i++) $stmt = $conn->prepare("insert famcomp(fullname,fage,frel,fcivil,fedu,foccup,finco,app_id) values (?,?,?,?,?,?,?,?)"); $stmt ->bind_param("ssssssss",$fullname[$i],$fage[$i],$frel[$i],$fcivil[$i],$fedu[$i],$foccup[$i],$finco[$i],$id); }
you bind_param
s , that's all. statement should execute
d. can executed several times 1 call prepare
:
$n = count($fullname); $stmt = $conn->prepare("insert famcomp(fullname,fage,frel,fcivil,fedu,foccup,finco,app_id) values (?,?,?,?,?,?,?,?)"); for($i=0; $i < $n; $i++) $stmt ->bind_param("ssssssss",$fullname[$i],$fage[$i],$frel[$i],$fcivil[$i],$fedu[$i],$foccup[$i],$finco[$i],$id); $stmt->execute(); }
Comments
Post a Comment