我在这里遇到错误,非常感谢您的帮助。
我的代码如下,这是我得到的错误:
PHP警告:mysqli_fetch_array()要求参数1为mysqli_result,在第14行的/home/SANDBOX/PHP/.php中给出为null
<?php
$con=mysqli_connect("localhost","USER","PASSWORD","DATABASE");
// Check connection
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if($_POST[process]=="btn_add"){
$result = mysqli_query($con,"INSERT INTO users (user, password, type) VALUES ('".$_POST['user']."','".$_POST['password']."','".$_POST['type']."')" );
}else if($_POST[process]=="btn_update"){
$result = mysqli_query($con,"UPDATE users SET user='".$_POST['user']."', password='".$_POST['password']."', type='".$_POST['type']."' WHERE id='".$_POST['id']."' ;");
}else if($_POST[process]=="btn_delete"){
$result = mysqli_query($con,"DELETE FROM users WHERE id='".$_POST['id']."';");
}while($result = mysqli_fetch_array($row)){
echo $row['type'] ;
}
mysqli_close($con);
?>
答案 0 :(得分:3)
mysqli_fetch_array($row)
至mysqli_fetch_array($result)
答案 1 :(得分:2)
always pass resource as an argument to mysql_fetch_array
}while($row = mysqli_fetch_array($result)){
echo $row['type'] ;
}
但我无法在你的代码中找到'select',你只使用'update'和'delete'。你不需要mysql_fetch_array。
mysql_fetch_array返回一个与获取的行对应的数组,并向前移动内部数据指针。
但您没有从数据库中选择任何内容,因此无需使用mysql_fetch_array。
*不要使用mysql_,因为它们被删除了。*
答案 2 :(得分:0)
语法错误:
$result = mysqli_query($con,"DELETE FROM users WHERE id='".$_POST['id']."';");
更改为:
$result = mysqli_query($con,"DELETE FROM users WHERE id='".$_POST['id']."'");