Need help on fetch_assoc() on a non-object in
Posted by: g/marry (---.cable.mindspring.com)
Date: July 09, 2009 04:40PM

I try to fetch data from mysql db , I repeatedly get the same message, Itry to figure out configuration issue,
syntax, ..... finaly I use the code which follws shortly

<html>
<head>
<title>Asa Trading</title>
<script type="text/javascript" language="JavaScript"></script>
</head>
<body>
<frame >
<col 20, *>
</frame>
<?php
include("header.php"winking smiley;
// require_once("dbconn.php"winking smiley;
$sql ="select * from 'tbproduct' " ;

$mysqli = new mysqli('localhost','root','');
$mysqli->select_db('asadb');

if ( (!$result = $mysqli->query($sql)))
{
echo "<table width=100%>" ;
while ( $row = $result->fetch_assoc())
{

echo "<tr>" ;
echo "<td >"; echo '.$row["prod_id"].'; echo "</td>";
echo "<td >"; echo '.$row["prod_name"].'; echo "</td>";
echo "<td >"; echo '.$row["prod_desc"].'; echo "</td>";
echo "<td >"; echo '.$row["prod_rate"].'; echo "</td>";
echo "<td >"; echo '.$row["prod_prc"].' ; echo "</td>";
echo "<td >"; echo '.$row["prod_qty"].' ; echo "</td>";
echo "</tr>";
}
echo "</table>"; ;

}
else
{
echo "<p>no data</p>";
}

$result->close();





; ?>
</body>
</html>

but when it runs, It comes like this

Fatal error: Call to a member function fetch_assoc() on a non-object in C:\wamp\www\asa\product.php on line 21

Options: ReplyQuote
Re: Need help on fetch_assoc() on a non-object in
Posted by: toumimi (---.237.115-78.rev.gaoland.net)
Date: July 09, 2009 05:01PM

Hi,

It's a php error due to a bad programming part...
if ( (!$result = $mysqli->query($sql)))

You should remove _!_ because if there is a result, then you can fetch it...
if ( ($result = $mysqli->query($sql)))

Why do you add single quotes into your sql ?
Try to remove them and you should be okay...

Note that this question should be asked into a php forum instead winking smiley

Florian

WampServer Patch (Screenshots)
Topic EN : www.wampserver.com
Topic FR : www.wampserver.com

Options: ReplyQuote
Re: Need help on fetch_assoc() on a non-object in
Posted by: g/marry (---.cable.mindspring.com)
Date: July 09, 2009 07:11PM

Thank u for ur help , it works kow........The reason I post here is that I was expecting configuration or servr problem....

Options: ReplyQuote
Re: Need help on fetch_assoc() on a non-object in
Posted by: toumimi (---.237.115-78.rev.gaoland.net)
Date: July 09, 2009 07:21PM

No problem winking smiley

Florian

WampServer Patch (Screenshots)
Topic EN : www.wampserver.com
Topic FR : www.wampserver.com

Options: ReplyQuote


Sorry, only registered users may post in this forum.