Solved

mysqli error...

Posted on 2013-05-28
9
528 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
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 82

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
 
LVL 82

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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

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

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 30

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
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…
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.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now