Jump to content

Recommended Posts

Hello,

 

I'm having a really big problem that I can't figure out. Basically, my first code snippet works fine, it gets the navigation from the database with no problem. But, when I'm trying to get another table from the database, I get this:

 

Fatal error: Call to a member function fetch_row() on a non-object in C:\wamp\www\domenicf.com\pages\762134.php on line 29

 

The navigation fetches fine, but the "pagecontent" doesn't. Here's my code.

 

<html> 
<head>  
<title> </title> 
<link href='../css/index.css' type='text/css' rel='stylsheet' /> 
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'> 
</head> 
<body> 
<div id='banner' /> 
</div> 
<div align='center' id='nav' /> 
<?php 
$mysqli = new mysqli(); 
$mysqli->connect('localhost', 'root', '', 'jesus'); 
error_reporting(E_ALL);
$query = 'SELECT name, url FROM navigation ORDER by id'; 
$result = $mysqli->query($query, MYSQLI_STORE_RESULT); 
while(list($name, $url) = $result->fetch_row()) 
printf("<a href='%s'>%s</a> | ", $url, $name); 
$result->close();
?> 
</div> 
<div id='content' /> 
<?php 
$mysqli = new mysqli(); 
$mysqli->connect('localhost', 'root', '', 'jesus'); 
error_reporting(E_ALL);
$newquery = 'SELECT id, postcontent FROM pages_sadasdasd ORDER by id'; 
$result2 = $mysqli->query($newquery, MYSQLI_STORE_RESULT); 
while(list($id, $pcontent) = $result2->fetch_row())
printf("%s %s", $id, $pcontent); 
if ($mysqli->errno) {
printf("Unable to connect to the database:<br /> %s",
$mysqli->error);
exit();
}
$result2->close();
?> 
</div> 
</body> 
</html> 

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/191530-fetch_row/
Share on other sites

U could try print mysql error after executing query. Something like this

 

//bla bla bla

$newquery = 'SELECT id, postcontent FROM pages_sadasdasd ORDER by id'; 
$result2 = $mysqli->query($newquery, MYSQLI_STORE_RESULT);
echo mysql_error();

//rest part of the code

 

any errors showed up?

Link to comment
https://forums.phpfreaks.com/topic/191530-fetch_row/#findComment-1009823
Share on other sites

U could try print mysql error after executing query. Something like this

 

//bla bla bla

$newquery = 'SELECT id, postcontent FROM pages_sadasdasd ORDER by id'; 
$result2 = $mysqli->query($newquery, MYSQLI_STORE_RESULT);
echo mysql_error();

//rest part of the code

 

any errors showed up?

 

Nope, no errors.

Link to comment
https://forums.phpfreaks.com/topic/191530-fetch_row/#findComment-1010041
Share on other sites

mysql_error() has nothing to do with using the mysqli OOP. You would need to use $mysqli->error

 

$mysqli->error(); returns this:

 

 

Fatal error: Call to undefined method mysqli::error() in C:\wamp\www\domenicf.com\test.php on line 7

 

<?php
//bla bla bla
$mysqli = new mysqli();
$mysqli->connect("localhost", "root", "", "jesus");
$newquery = 'SELECT id, postcontent FROM pages_sadasdasd ORDER by id'; 
$result2 = $mysqli->query($newquery, MYSQLI_STORE_RESULT);
echo $mysqli->error();

//rest part of the code
?>

Link to comment
https://forums.phpfreaks.com/topic/191530-fetch_row/#findComment-1010049
Share on other sites

I can't see concrete mistake in your code(or maybe I am blind), the way I would search for problem I would try then for example

$result2 = $mysqli->query($newquery, MYSQLI_STORE_RESULT); 
$result2->fetch_row();
echo $mysqli->error;

//...

or u could try execute your query 'SELECT id, postcontent FROM pages_sadasdasd ORDER by id' via phpMyAdmin(or some other tool) and see what result is

 

Anyway table name `pages_sadasdasd` is realy suspicious couse it looks like random s*it and it's hard to beleave that some CMS names tables like this... plus name of table `navigation` looks pretty normal and self explanatory.

Link to comment
https://forums.phpfreaks.com/topic/191530-fetch_row/#findComment-1010050
Share on other sites

I can't see concrete mistake in your code(or maybe I am blind), the way I would search for problem I would try then for example

$result2 = $mysqli->query($newquery, MYSQLI_STORE_RESULT); 
$result2->fetch_row();
echo $mysqli->error;

//...

or u could try execute your query 'SELECT id, postcontent FROM pages_sadasdasd ORDER by id' via phpMyAdmin(or some other tool) and see what result is

 

Anyway table name `pages_sadasdasd` is realy suspicious couse it looks like random s*it and it's hard to beleave that some CMS names tables like this... plus name of table `navigation` looks pretty normal and self explanatory.

 

I'll explain...

 

The CMS takes user input, so if the page name is "sadasdasd" it will create a table "pages_sadasdasd".

 

Edit: Epic failure. I sincerely thought it wasn't a MySQL problem, but the column was "pagecontent" instead of "postcontent". Sorry :(

Link to comment
https://forums.phpfreaks.com/topic/191530-fetch_row/#findComment-1010183
Share on other sites

I dont know how much percently u are sure that it's not MySQL problem but what i see it's exactly this(course I may be wrong)

 

Here how it goes:

Error says "Call to a member function fetch_row() on a non-object"

That means that variable $result2 is not a object and it doesn't have method fetch_row() (also it doesnt have any other methods/properties since $result2 is not object)

Ok now let's look how and where we get $result2?

By $mysqli->query($newquery, MYSQLI_STORE_RESULT);

Since code above with almost exact logics worked fine I know that $mysqli->query returns object that u can fetch and work with on success.

But in this case we have failure and only culprit (that I can think of)here is your sql 'SELECT id, postcontent FROM pages_sadasdasd ORDER by id'.

 

I dont know what wrong with sql is but most possibe wrong field names,wrong table name or non existing table...

 

Or maybe u mistspelled connection password? is that possible?

Link to comment
https://forums.phpfreaks.com/topic/191530-fetch_row/#findComment-1010200
Share on other sites

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.