Jump to content

Fatal error: Call to a member function fetch_array()


ThatMSG

Recommended Posts

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

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
  }

 

 

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?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.