我知道上面的消息发生了错误的MySQL查询,但是我的MySQL查询在这段代码中出了什么问题? 我做了很多研究才找到它,但无法找到解决方案。 表名:pic_msg 列:image_path,ip,index(auto_increment)
<?php
$con = mysqli_connect("localhost","root","password","my_database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
<?php
$test_ip = "test-ip";
$sql = "SELECT image_path FROM pic_msg WHERE ip = '$test_ip' ORDER BY index DESC LIMIIT 1";
$result = mysqli_query($con, $sql);
$rowcount = mysqli_num_rows($result);
if ($rowcount > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo $row["image_path"]."<br>";
}
} else {
}
mysqli_close($con);
?>
答案 0 :(得分:1)
index
是一个保留字 - 你应该逃避它。此外,您有一个拼写错误 - 它是limit
,而不是limiit
:
$sql = "SELECT `image_path` FROM `pic_msg` WHERE `ip` = '$test_ip' ORDER BY `index` DESC LIMIT 1";