php mysqli获取对象

时间:2018-05-20 16:44:13

标签: php html mysqli

任何人都可以在我的PHP代码中发现任何错误吗?

<?php
$keyword=$_GET['keyboards'];
$sql = "SELECT *FROM MyGuests WHERE lastname LIKE '$keyword'";
$result=mysqli_query($conn,$sql);
$sss=mysqli_num_rows($result);

if($sss)
{
    while($row=mysqli_fetch_object($result)){       
        **echo "id: " . $row['lastname'].  "<br>";**            
    }
}
?>

问题在这里:

echo "id: " . $row['lastname'].  "<br>";

1 个答案:

答案 0 :(得分:-1)

尝试

while ($row =$result->fetch_object()) {
        echo $reg->lastname;
        }

while ($row =$result->fetch_object()) {
        echo $reg['lastname'];
        }