vinson89 Posted May 22, 2014 Share Posted May 22, 2014 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);? Quote Link to comment https://forums.phpfreaks.com/topic/288666-how-to-fix-extract-warning/ Share on other sites More sharing options...
trq Posted May 22, 2014 Share Posted May 22, 2014 Make sure that $row is what extract expects, an array. We need to see the code that creates $row in order to be of more help. Quote Link to comment https://forums.phpfreaks.com/topic/288666-how-to-fix-extract-warning/#findComment-1480392 Share on other sites More sharing options...
vinson89 Posted May 22, 2014 Author Share Posted May 22, 2014 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/288666-how-to-fix-extract-warning/#findComment-1480394 Share on other sites More sharing options...
Solution trq Posted May 22, 2014 Solution Share Posted May 22, 2014 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 } } Quote Link to comment https://forums.phpfreaks.com/topic/288666-how-to-fix-extract-warning/#findComment-1480395 Share on other sites More sharing options...
vinson89 Posted May 22, 2014 Author Share Posted May 22, 2014 thanks, i would like to try it. Quote Link to comment https://forums.phpfreaks.com/topic/288666-how-to-fix-extract-warning/#findComment-1480396 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.