我試圖做多在PHP中刪除,但要得到一個錯誤:多刪除錯誤:「試圖獲得非對象的屬性在」
Trying to get property of non-object in...
我不知道爲什麼這是發生 - 我做錯了什麼?
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
//--------------------------------------DELETE RECORD - DATABASE-----------------------------------------------
//Obtain login credentials
require_once 'login.php';
//Create connection to database
$conn = new mysqli($hn, $un, $pw, $db);
//Check if connection succeeded
if ($conn->connect_error) die($conn->connect_error);
//Verify if user already chose record to be deleted from the database table
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
$id = $_GET['id'];
//Delete record from table
$query = "DELETE FROM jazz WHERE id=$id";
$result = $conn->query($query);
//If query fails, display error message
if (!$result) {
echo "DELETE failed: $query <br />" . $conn->error . "<br /><br />";
} else {
//If query succeeded, display success message
echo "Record deleted successfully!";
}
}
//--------------------------------------RETRIEVE RECORDS - DATABASE-----------------------------------------------
//Retrieve records
$query = "SELECT id, year, artist, album, Publisher, subgenre, rating FROM jazz";
$result = $conn->query($query);
//Check if query succeeded
if (!$result) die ("Database access failed: " . $conn->error);
//Sets up Multi Delete Ability
**if(isset($_POST['delete']))
{
$cnt=array();
$cnt=count($_POST['checkbox']);
for($i=0;$i<$cnt;$i++)
{
$del_id=$_POST['checkbox'][$i];
$query = "DELETE FROM jazz WHERE id='$.id'";
$result = $conn->query($query);
if (!$result) echo "DELETE failed: $query<br>" .
$conn->error . "<br><br>";
# mysqli_query($conn , $result);
}
}**
echo "<!DOCTYPE html>";
echo "<html>";
echo "<head>";
echo "<title>Delete Record</title>";
echo "<link rel='stylesheet' href='view.css'>";
echo "</head>";
echo "<body>";
echo "<header><h1>Delete Record</h1></header>";
echo "<form action = 'delete_test.php' method = 'post'>";
echo "<table>";
echo "<tr class='row'>";
echo "<th class='col-1'>ID</th>";
echo "<th class='col-1'>Year</th>";
echo "<th class='col-2'>Artist</th>";
echo "<th class='col-3'>Album</th>";
echo "<th class='col-4'>Rating</th>";
echo "<th class='col-5'>Subgenre</th>";
echo "<th class='col-6'>Publisher</th>";
echo "<th class='col-7'>Delete</th>";
echo "</tr>";
**//Display retrieved records ----------------START
if (is_object($result)){
$rows = $result->num_rows;
}
$rows = $result->num_rows;** ----------------END
for ($j = 0 ; $j < $rows ; ++$j) {
$result->data_seek($j);
$row = $result->fetch_array(MYSQLI_NUM);
echo "<tr class='row'>";
echo "<td class='col-1'>" . $row[0] . "</td>";
echo "<td class='col-2'>" . $row[1] . "</td>";
echo "<td class='col-3'>" . $row[2] . "</td>";
echo "<td class='col-4'>" . $row[3] . "</td>";
echo "<td class='col-5'>" . $row[4] . "</td>";
echo "<td class='col-6'>" . $row[5] . "</td>";
echo "<td class='col-7'>" . $row[6] . "</td>";
echo "<td class='col-8'><input type = 'checkbox' input name = 'checkbox[]' value='.$row[0].'</td>";
echo "</tr>";
}
echo "<input type = 'submit' value = 'delete' name = 'delete' class = 'button'>";
echo "</table></form></body></html>";
echo "<a href='Project - Homepage.html'>Home</a>";
//Close connection
$conn->close();
?>
在哪一行? –
它在行85 – GOAT
什麼是85行?我們不能計數到85示出了它在問題 –