0
我在PHP新,並繼續得到「試圖獲得非對象的屬性」的錯誤。我的目標是允許用戶鍵入一個客戶ID併爲其返回該特定客戶的信息。我的代碼在下面,並且都在一個PHP文件中。該錯誤指出我在第34行(具有"while($row = mysqli_fetch_assoc($result)) {"
的行)上發生錯誤。試圖讓非對象的物業PHP
<!doctype html>
<html lang="en-US">
<Head>
</Head>
<Body>
<style> table, TH {width: 500px; height: 20px;} </style>
<form action="php.php" method="post">
Customer ID: <input type="text" name="customerid"><br>
<input type="submit">
</form>
<?php
if(isset($_POST['customerid'])) {
$servername = "localhost";
$username = "test";
$password = "";
$dbname = "test";
$cust = mysql_real_escape_string($_POST['customerid']);
// Create connection
$conn = mysqli_connect($servername, $username, $password);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "<Table>". "<TH>Customer Name</TH>"."<TH>barr</TH>"."<TH>Cusomter Id</TH></Table>";
$sql = "SELECT customer_name, barr, customer_id FROM churn.data WHERE customer_id =". $cust ."";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "<Table><TH>". $row["customer_name"]. "</TH><TH>". $row["barr"]."</TH><TH>". $row["customer_id"]."</TH></Table>";
}
}
else {
echo "0 results";
}
mysqli_close($conn);
}
?>
</body>
</html>
我改變了一些信息,因爲我關心隱私,所以希望不會影響任何東西。
任何幫助將不勝感激。
感謝
你能的print_r($行)? – aldrin27