Jump to content

how to fix extract warning


vinson89
Go to solution Solved by trq,

Recommended Posts

Hi, I got 1 warning form the server, It said:

 

Warning: extract() expects parameter 1 to be array, null given in /home/tz005/public_html/COMP1687/edit.php on line 113

 

extract($row);

 

how to fix the warning,should I replace it with extract($array);?

Link to comment
Share on other sites

Here is the php code:

 

<?php
//include database connection
include 'dbconnect.php';
 
// if the form was submitted/posted, update the item
if($_POST){
 
    //write query
    $sql = "UPDATE 
                item_information 
            SET
                itemtitle = ?, 
                itemdescription = ?,
                date = ?,
            WHERE 
                itemid= ?";
     
    $stmt = $mysqli->prepare($sql);
     
    // you can bind params this way,
    // if you want to see the other way, see our add.php
    $stmt->bind_param(
        'sssi', 
        $_POST['itemtitle'], 
        $_POST['itemdescription'],
        $_POST['date'],
        $_POST['itemid']
    );
     
    // execute the update statement
    if($stmt->execute()){
        echo "Item was updated.";
         
        // close the prepared statement
        $stmt->close();
    }else{
        die("Unable to update.");
    }
}
 
$sql = "SELECT 
            itemid, itemtitle, itemdescription, date
        FROM 
            item_information
        WHERE 
            id = \"" . $mysqli->real_escape_string($_GET['itemid']) . "\"
        LIMIT 
            0,1";
 
// execute the sql query
$result = $mysqli->query( $sql );
 
//get the result
$row = $result->fetch_assoc();
 
extract($row);
 
//disconnect from database
$result->free();
$mysqli->close();
?>
Link to comment
Share on other sites

  • Solution

I would highly recommend not using extract at all in that situation, but anyway, you still need to check that your query succeeds and returns actual results.

 

if ($result = $mysqli->query( $sql )) {
  if ($row = $result->fetch_assoc()) {

    // $row contains data

  }
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.