Solved

mysqli error...

Posted on 2013-05-28
9
537 Views
Last Modified: 2013-05-28
Hi, I am running this query and I keep get the following error, can someone let me know what is wrong here?


Warning: mysqli::prepare(): Couldn't fetch mysqli in /var/www/voicebox/home_user.php on line 87

Fatal error: Call to a member function bind_param() on a non-object in /var/www/voicebox/home_user.php on line 88


$ph=$mysqli->prepare("select did_number from did_numbers where assigned_to=? and did_status='1'");
   $ph->bind_param("i",$userid);
   $ph->execute();
   $ph->fetch();
   $ph ->store_result();   
   $phCount=$ph->num_rows;
   if($phCount==0)
   $rowCount="No  Lines";
       else {
		       $rowCount=$phCount;
                 }   

Open in new window

0
Comment
Question by:aej1973
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 5

Expert Comment

by:sriramiyer
ID: 39203475
insert this sqlstr code for debugging purpose to get valid sqlstr or not first,

$sqlstr="select did_number from did_numbers where assigned_to=? and did_status='1'";
echo $sqlstr . "</br>";
exit;
mysqli->prepare("select did_number from did_numbers where assigned_to=? and did_status='1'");
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39203488
Do you have code to open the connection on that page before those lines?  http://us3.php.net/manual/en/mysqli.construct.php
0
 

Author Comment

by:aej1973
ID: 39203500
yes, the connection is open..
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39203553
See the first user comment here http://php.net/manual/en/mysqli.query.php about "Couldn't fetch mysqli".
0
 

Author Comment

by:aej1973
ID: 39203558
ok, let me check.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39203562
You may also be missing a statement according to the example here: http://www.php.net/manual/en/mysqli.prepare.php
0
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 300 total points
ID: 39203565
Try this:

$ph=$mysqli->prepare("select did_number from did_numbers where assigned_to=? and did_status='1'");
if ($ph === false){
  die(mysqli->error();
}
$ph->bind_param("i",$userid);

Since mysqli->prepare return false if it fails, this way you'll can get the specific mysqli error-
0
 

Author Comment

by:aej1973
ID: 39203588
Marcus, this is the error I am getting...

Fatal error: Call to undefined method mysqli::error() in /var/www/voicebox/home_user.php on line 92
0
 

Author Comment

by:aej1973
ID: 39203599
solved. Thanks Marcus.

if ($ph == false){
       die($mysqli->error);
           }
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question