下面的代碼應該允許您查看朋友列表 並編輯或從同一頁面刪除。查看工作,但刪除和更新不。任何幫助,將不勝感激。 查看代碼:爲什麼mysqli查詢返回false?
$query ="SELECT * FROM tblFriends";
$result = mysqli_query($conn,$query);
while($row =$result->fetch_assoc()){
$fname=$row['fname'];
$lname=$row['lname'];
$address=$row['address'];
$desc=$row['description'];
$zip=$row['zip'];
$city=$row['city'];
$state=$row['state'];
$id =$row['key'];
echo
"<tr>
<td><input type='text' name='fname' value='$fname'/></td>
<td><input type='text' name='lname' value='$lname'/></td>
<td><input type='text' name='address' value='$address'/></td>
<td><input type='text' name='city' value='$city'/></td>
<td><input type='text' name='desc' value='$desc'/></td>
<td><input type='text' name='state' value='$state'/></td>
<td><input type='submit' name='Edit' value='Edit'/></td>
<td><input type='submit' name='Delete' value='Delete'/></td>
<input type='hidden' name='id' value='$id'/>
<input type='hidden' name='zip' value='$zip'/>
</tr>";
}
更新代碼:
if(isset($_POST['Edit'])){
$fname1=$_POST['fname'];
$lname1=$_POST['lname'];
$city1=$_POST['city'];
$state1=$_POST['state'];
$zip1=$_POST['zip'];
$desc1=$_POST['desc'];
$address1=$_POST['address'];
$id1=$_POST['id'];
$UpdateQuery ="UPDATE tblfriends SET fname='$fname1', lname='$lname1',city='$city1',address='$address1',zip='$zip1',state='$state1' WHERE id=$id1";
echo $id1;
if(mysqli_query($conn,$UpdateQuery)){
echo "Updated";
}else{
echo "Not Updated";
}
}
刪除代碼: 這mysqli_query
和更新一個都返回假
if(isset($_POST['Delete'])){
$id2 =$_POST['id'];
$deleteQuery= "DELETE FROM tblfriends WHERE id=$id2";
if(mysqli_query($conn,$deleteQuery)){
echo "Deleted";
}else{
echo "Not Deleted";
}
你有錯誤報告打開?你應該經常檢查你的查詢是否有錯誤。 – Andrius
@Andrius我不知道有錯誤報告,我怎麼知道它是否在打開? – DohnJoe
'ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(E_ALL);'幫助。如果您有任何錯誤,請編輯您的問題。 – Andrius