Solved

mysqli error...

Posted on 2013-05-28
9
536 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Suggested Solutions

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses how to implement server side field validation and display customized error messages to the client.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

730 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