ThatMSG Posted May 22, 2011 Share Posted May 22, 2011 Hi guys. I need some help, because i'm stuck I'm getting this error and cand figure out what im doin wrong. Fatal error: Call to a member function fetch_array() on a non-object in C:\xampp\htdocs\cms\webklex\theme\admin\edit_content.php on line 16. The Code around it: include "../config/config.php"; $host = htmlspecialchars($_SERVER["HTTP_HOST"]); $uri = rtrim(dirname(htmlspecialchars($_SERVER["PHP_SELF"])), "/\\"); $extra = "show_content.php"; if (empty($_POST["titel"])) { $id = (isset($_GET["id"])) ? (int)$_GET["id"] : false; $result = $db->query("SELECT * FROM `content` WHERE `id` = ".$db->real_escape_string($id).""); $row = $result->fetch_array(MYSQLI_ASSOC); $db->free_result; unset($result); } $ide = (isset($_GET["id"])) ? (int)$_GET["id"] : false; $result = $db->query("SELECT `id_position` FROM `content` WHERE `id` = ".$db->real_escape_string($ide).""); $zeile = $result->fetch_array(MYSQLI_ASSOC); ---->This is line 16 $db->free_result; unset($result); $id_position_real = $zeile['id_position']; if ($id_position_real == 1) { $id_position_real = 1; }else{ $id_position_real= 0; } if ($id_position_real == 1) { $id_position_real_none = 0; }else{ $id_position_real_none = 1; } ?> Thx ThatMSG Quote Link to comment https://forums.phpfreaks.com/topic/237153-fatal-error-call-to-a-member-function-fetch_array/ Share on other sites More sharing options...
mgoodman Posted May 22, 2011 Share Posted May 22, 2011 I think that your problem is that $db->query() is probably returning false. That means that your query has failed. Try to var_dump $result and see if it is false. Quote Link to comment https://forums.phpfreaks.com/topic/237153-fatal-error-call-to-a-member-function-fetch_array/#findComment-1218834 Share on other sites More sharing options...
ThatMSG Posted May 22, 2011 Author Share Posted May 22, 2011 Well thanks... Now hes updating the data but wont show it anymore... bool(false) Notice: Undefined property: mysqli::$free_result in C:\xampp\htdocs\cms\webklex\theme\admin\edit_content.php on line 17 $ide = (isset($_GET["id"])) ? (int)$_GET["id"] : false; $result = $db->query("SELECT `id_position` FROM `content` WHERE `id` = ".$db->real_escape_string($ide).""); var_dump($result); $db->free_result; ---->Line 17 unset($result); Notice: Undefined index: id_position in C:\xampp\htdocs\cms\webklex\theme\admin\edit_content.php on line 20 $id_position_real = $zeile['id_position']; ---->line 20 if ($id_position_real == 1) { $id_position_real = 1; }else{ $id_position_real= 0; } if ($id_position_real == 1) { $id_position_real_none = 0; }else{ $id_position_real_none = 1; } <br /> <b>Notice</b>: Undefined variable: row in <b>C:\xampp\htdocs\cms\webklex\theme\admin\edit_content.php</b> on line <b>72</b><br /> <tr> <td>Titel: </td> <td><input type="text" name="titel" value="<?php echo htmlspecialchars($row["titel"]); ?>" /></td> ----> Line 72 </tr> Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\cms\webklex\theme\admin\edit_content.php:82) in C:\xampp\htdocs\cms\webklex\theme\admin\edit_content.php on line 106 if(isset($_POST['id'])) { $id = (int)$_POST["id"]; $titel = $_POST["titel"]; $name = $_POST["name"]; $content = $_POST["content"]; $id_position = $_POST["id_position"]; $db->query("UPDATE content SET id_position=0 WHERE id_position=1;"); $db->query("UPDATE `content` SET `titel` = '".$db->real_escape_string($titel)."', `name` = '".$db->real_escape_string($name)."', `content` = '".$db->real_escape_string($content)."', `id_position` = '".$db->real_escape_string($id_position)."' WHERE `id` = ".$db->real_escape_string($id).""); $db->close(); header("Location: http://$host$uri/$extra"); ----->line 106 } Quote Link to comment https://forums.phpfreaks.com/topic/237153-fatal-error-call-to-a-member-function-fetch_array/#findComment-1218838 Share on other sites More sharing options...
mgoodman Posted May 22, 2011 Share Posted May 22, 2011 All of those errors are rather self explanatory. For the first one you don't have your () at the end of free_result. The last one is because of all of the error messages sending page content before that header call. You also seem to have deleted the line where $row is assigned, which would explain the third error. The second one is probably due to the query failure. Also, where does $zeile come from? Quote Link to comment https://forums.phpfreaks.com/topic/237153-fatal-error-call-to-a-member-function-fetch_array/#findComment-1218840 Share on other sites More sharing options...
ThatMSG Posted May 22, 2011 Author Share Posted May 22, 2011 hmm how can <input type="hidden" name="id" value="<?=$id?>" /> send the headerinformation? Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\cms\webklex\theme\admin\edit_content.php:74) Quote Link to comment https://forums.phpfreaks.com/topic/237153-fatal-error-call-to-a-member-function-fetch_array/#findComment-1218853 Share on other sites More sharing options...
mgoodman Posted May 22, 2011 Share Posted May 22, 2011 You must send headers before any page content is sent. Anything that gets echoed onto the page is content, even if it can't actually be seen once the page is rendered. If you need to generate content before you determine the headers then you can utilize output buffering to "save" the content and then send it out after you set the headers. http://php.net/manual/en/book.outcontrol.php Quote Link to comment https://forums.phpfreaks.com/topic/237153-fatal-error-call-to-a-member-function-fetch_array/#findComment-1218856 Share on other sites More sharing options...
ThatMSG Posted May 24, 2011 Author Share Posted May 24, 2011 Hey thx but i never worked with Output Control. Would u tell me what i should change to make it work? Quote Link to comment https://forums.phpfreaks.com/topic/237153-fatal-error-call-to-a-member-function-fetch_array/#findComment-1219490 Share on other sites More sharing options...
ThatMSG Posted May 24, 2011 Author Share Posted May 24, 2011 I just solved... Thx mgoodman!!! Quote Link to comment https://forums.phpfreaks.com/topic/237153-fatal-error-call-to-a-member-function-fetch_array/#findComment-1219491 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.