我从下面提供的代码中收到以下错误:
警告:mysqli_query()要求参数1为mysqli,第7行的C:\ xampp \ htdocs \ index.php中给出的字符串
警告:mysqli_error()需要在第8行的C:\ xampp \ htdocs \ index.php中给出1个参数0 ERROR:
<?php
$conn = mysqli_connect("localhost","root","");//server, username and password are your server address and access details
if(!$conn)
die("cannot connect to mysql server" . mysqli_error());
mysqli_select_db( $conn,"website_data");
$sql = "INSERT INTO IP_Logs (IP) VALUES(" . $_SERVER['REMOTE_ADDR'] . ")";
if(!mysqli_query($sql,$conn))
die("ERROR: " .mysqli_error());
mysqli_close($con);
?>
答案 0 :(得分:1)
你在mysqli_query
电话中的参数错误;您的数据库连接应该是第一个:
if(!mysqli_query($conn,$sql))
要解决您的其他错误,您需要将$conn
传递给mysqli_error
来电:
die("ERROR: " .mysqli_error($conn));
现在,要使用SQL语法解决错误,请尝试在$_SERVER['REMOTE_ATTR']
周围的查询中添加引号,如下所示:
$sql = "INSERT INTO IP_Logs (IP) VALUES(\"" . $_SERVER['REMOTE_ADDR'] . "\")";