Update an array php mysql -
i'm trying update in database 2 array depends on each others. want know if possible use foreach()
update data?
[reponse] => array ( [0] => reponse 1 [1] => reponse 2 [2] => reponse 3 )
file.php
foreach ($reponse $key=>$value) { $values= mysql_real_escape_string($value); $valuesch= mysql_real_escape_string($chimp[$key]); $query2 = mysql_query("update reponses set nom_reponse=$values,id_categorie='$categorie',correct='$valuesch' id_question='$id_question' ") or die(mysql_error()); } if ($query2) { echo "<br><div class='alert alert-info alert-dismissable'><button aria-hidden='true' data-dismiss='alert' class='close' type='button'>×</button>"; echo "reponse modifer avec succes!! "; echo "</div> "; } else { echo " erreur reponse!! "; }
i want know problem in code? , how update correctly?
after google , understanding how use array find solution , update array in database call each value key way :
[reponse] => array ( [0] => reponse [1] => reponse b [2] => reponse c ) [id_reponse] => array ( [0] => 19 [1] => 20 [2] => 21 ) foreach ($reponse $key=>$value) { $values= mysql_real_escape_string($value); $valuescheck= mysql_real_escape_string($chimp[$key]); $valuesidr= mysql_real_escape_string($id_reponse[$key]); $query2 = mysql_query("update reponses set nom_reponse='$values',correct='$valuescheck' id_reponse='$valuesidr' ") or die(mysql_error()); } if ($query2) { echo "<br><div class='alert alert-info alert-dismissable'><button aria-hidden='true' data-dismiss='alert' class='close' type='button'>×</button>"; echo "reponse modifer avec succes!! "; echo "</div> "; } else { echo " erreur reponse!! "; }
Comments
Post a Comment