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);? 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. 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(); ?> Link to comment https://forums.phpfreaks.com/topic/288666-how-to-fix-extract-warning/#findComment-1480394 Share on other sites More sharing options...
trq Posted May 22, 2014 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 } } 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. 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
Archived
This topic is now archived and is closed to further replies.