Jump to content

Recommended Posts

Hi all,

 

I'm getting the following error, but I cannot see why:

 

ERROR:

Fatal error: Call to a member function fetch_assoc() on a non-object in {filepath} on line 36

 

CODE:

<?php 

ini_set('display_errors',1); 
error_reporting(E_ALL);

require_once("aconfig.php");

$eid = $_GET["event"];

echo '<html>
<head>
<title>Admin Control Panel :: PRINT TICKETS</title>
<style type="text/css">
body {
font-family: Helvetica, Arial;
}
</style>
</head>
<body>';

//start classes
$db = new db();

//connect to DB
//attempt it
$sql = new mysqli(db::$config['host'], db::$config['user'], db::$config['pass'], db::$config['db']);
//check for ERR
	if (mysqli_connect_errno()) {
	    printf("Connect failed: %s\n", mysqli_connect_error());
    	exit();
	}
	//

if($eid == "edit"){
echo '<h1>SELECT EVENT</h1>
	<p>Select an event to print tickets for</p>
	<p>';
$query = 'SELECT * from `tickets` ORDER by id';
$query = $sql->real_escape_string($query);
// Perform Query
$result = $sql->query($query);
// Loop Through Result
while ($row = $result->fetch_assoc()) {

echo '− <a href="ptickets.php?event='.$row[id].'">'.$row[event_name].'</a> <br />';
}
echo '</p>';
}else {
	$query2 = 'SELECT * from `orders` WHERE `id` = '.$eid.', paid = "1"';
	$query2 = $sql->real_escape_string($query2);
	// Perform Query
	$result2 = $sql->query($query2);
	// Loop Through Result
	while ($row2 = $result2->fetch_assoc()) {
		echo '<table cellspacing="1" cellpadding="1" border="1" width="400">
    <tbody>
        <tr>
            <td colspan="2"><strong>Online Ticket</strong></td>
        </tr>
        <tr>
            <td width="300">
            <p>Event: <strong>'.$row2[eventname].'</strong></p>
            <p>Holder Name: <strong>'.$row2[name].'</strong></p>
            <p>No. Adult tickets: <strong>'.$row2[adult_tix].'</strong><br />
            No. Concession tickets: <strong>'.$row2[concess_tix].'</strong></p>
            </td>
            <td>
            <p><u>STAFF</u></p>
            <p><em>Rip this side off once ticket holder has entered.</em></p>
            </td>
        </tr>
    </tbody>
</table>
<p> </p>';
	}
}


echo '</body></html>';

?>

 

What the script does:

 

if the page is ?event=edit, it lists all the available events.

 

If not, it checks what event id is at ?event and lists that ID from the DB.

 

What's wrong with it?

 

Thanks

I think this line should be:

 

   while ($row = $sql->fetch_assoc($result)) {

 

$sql is your object, which is an instance of the class db.  $result is the resource id that was returned from:

 

   $result = $sql->query($query);

 

It doesn't make sense to invoke a method from $result.  Instead you should give the resource id ($result) to the fetch_array() method which comes from the 'db' class.

I think this line should be:

 

   while ($row = $sql->fetch_assoc($result)) {

 

$sql is your object, which is an instance of the class db.  $result is the resource id that was returned from:

 

   $result = $sql->query($query);

 

It doesn't make sense to invoke a method from $result.  Instead you should give the resource id ($result) to the fetch_array() method which comes from the 'db' class.

 

Thanks,

 

It now gives the following error:

 

Fatal error: Call to undefined method mysqli::fetch_assoc() in {filepath} on line 54

 

Any ideas?

 

Thanks

  • 1 year later...

A) Please start your own thread for your problem,

 

B) The error means what it says, what ever variable you are using in the $result->fetch_assoc() statement isn't an object because your query failed and returned a false value instead of a result object or you overwrote the variable somewhere else in your code.

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.