,所以我得到這個錯誤:插入foreach循環
注意:未初始化字符串偏移
我要插入的單選按鈕的檢查單選按鈕設置在每一行的值我的桌子。
這意味着我的每一行我有這個問題ll單選按鈕設置ll評論。
調查表。
<?php
$link=Mysqli_connect($host,$login,$pass,$dbname);
$un = 0;
$msgerror = "Veuillez remplir tous les champs ";
if(isset($_POST["bouton10"])) {
$id = $_REQUEST["Picolo4"];
$Nom = $_REQUEST["Picolo1"];
$Prenom = $_REQUEST["Picolo2"];
$Email = $_REQUEST["Picolo3"];
if ($id !="" && $Nom !="" && $Prenom !="" && $Email !="") {
$recherche= "SELECT Ref,Question,Choix,Commentara FROM questionnaire WHERE Qref ='$id'";
mysqli_query($link,$recherche);
$result= mysqli_query($link,$recherche);
$num_results = $result->num_rows;
while ($row = mysqli_fetch_assoc($result)) {
$Ref =$row["Ref"];
$Question =$row["Question"];
$un++;
echo" <tr bgcolor=\"white\">
<td>$Question position: $un </td>
<td>
<input type=\"radio\" name =\"$un\" id =\"un\" value = \"3\">
<input type=\"radio\" name =\"$un\" id =\"un\" value = \"2\">
<input type=\"radio\" name =\"$un\" id =\"un\" value = \"1\">
<input type=\"radio\" name =\"$un\" id =\"un\" value = \"0\">
<input type=\"radio\" name =\"$un\" id =\"un\" value = \"0\">
</td>
<td width = \"60\"> <textarea> </textarea> </td>
</tr>
</div>
</div>";
}
} else {
echo "<script type='text/javascript'>alert('$msgerror')</script>";
}
}
//The part with the problem //
$un = 1;
if (isset($_POST["bouton11"])) {
$i= 0 ;
while(isset($_POST[$un])) {
//Line 71 //
$choix = $_POST["$un"][$i];
$enregistrer = "INSERT INTO questionnaire(Choix) VALUES('$choix') ";
$un++;
$i++;
mysqli_query($link, $enregistrer);
}
}
?>
這很可能是因爲'$ _REQUEST [x]'值不存在,請嘗試類似'$ id =!empty($ _ REQUEST [「Picolo4」])? $ _REQUEST [「Picolo4」]:「」;'**但是**請清理您的輸入並使用準備好的語句。你的代碼非常容易受到SQL注入的影響。 – Peon
仍然得到相同的錯誤 –
什麼是完整的錯誤?它應該告訴你這是什麼線,因此,你可以檢查你想要讀的索引,那還沒有。即,'$ choix = $ _POST [「$ un」] [$ i]'也看起來可疑 – Peon