The Architect
The Architect

Reputation: 353

PHP error in query with parameters missing

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

Answers (3)

R R
R R

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.

Read manual here

*Dont use mysql_ as they are depracated.*

Upvotes: 2

Chetan hada
Chetan hada

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

worenga
worenga

Reputation: 5856

mysqli_fetch_array($row) to mysqli_fetch_array($result)

Upvotes: 3

Related Questions