Reputation: 353
I am having an error here and your help would be much appreciated.
My code is below and this is the error I am getting:
PHP Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home/SANDBOX/PHP/.php on line 14
<?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);
?>
Upvotes: 0
Views: 1323
Reputation: 2956
always pass resource as an argument to mysql_fetch_array
}while($row = mysqli_fetch_array($result)){
echo $row['type'] ;
}
But i cant find 'select' in your code,you are using only 'update' and 'delete'.you dont need mysql_fetch_array.
mysql_fetch_array Returns an array that corresponds to the fetched row and moves the internal data pointer ahead.
but you are not selecting anything from database so there is no need to use mysql_fetch_array.
*Dont use mysql_ as they are depracated.*
Upvotes: 2
Reputation: 1
syntax error:
$result = mysqli_query($con,"DELETE FROM users WHERE id='".$_POST['id']."';");
change to:
$result = mysqli_query($con,"DELETE FROM users WHERE id='".$_POST['id']."'");
Upvotes: 0