Solved

Help with PHP query

Posted on 2012-04-02
3
245 Views
Last Modified: 2012-06-27
I'm struggling to get this query working.

I think my syntax is wrong, but I don't know how I need to modify it.

$connection = @new mysqli(HOSTNAME, MYSQLUSER, MYSQLPASS, MYSQLDB);
if ($connection->connect_error) {
	die('Connect Error: ' . $connection->connect_error);
} 

else {

	$query = "SELECT * FROM `Pet` WHERE 'CustomerNumber' = '$customer'";
	

	$result = '';
	$result = $connection->query($query);

	while($result = $result_obj->fetch_array(MYSQLI_ASSOC)) {
		print_r($result);
		echo '<br />';
	}

	

}

Open in new window

0
Comment
Question by:InquisitiveProgrammer
3 Comments
 
LVL 24

Expert Comment

by:johanntagle
ID: 37798738
CustomerNumber should be enclosed by backticks, not single quotes.  Just like what you did with Pets.
0
 
LVL 1

Author Comment

by:InquisitiveProgrammer
ID: 37798795
Unfortunately that isn't the problem I'm having. I have added the complete code below:

<?php session_start(); ?>

<HTML>

<HEAD><TITLE>Florida Pet Clinics Inc.</TITLE>

</HEAD>

<BODY>

<H1 ALIGN="CENTER">Florida Pet Clinics Inc. </H1>

<?php

$customer = $_SESSION['curr_customer'];

echo "You are viewing the information for customer number " . $customer;

?>

<P><A HREF="addpetinfo.php">Add New Pet</A>

<?php>

define("MYSQLUSER", "???");
define("MYSQLPASS", "???");
define("HOSTNAME", "???");
define("MYSQLDB", "???");

$connection = @new mysqli(HOSTNAME, MYSQLUSER, MYSQLPASS, MYSQLDB);
if ($connection->connect_error) {
	die('Connect Error: ' . $connection->connect_error);
} 

else {

	$query = "SELECT * FROM `Pet` WHERE `CustomerNumber` = '$customer'";
	

	$result = '';
	$result = $connection->query($query);

	while($result = $result_obj->fetch_array(MYSQLI_ASSOC)) {
		print_r($result);
		echo '<br />';
	}

	

}

?>

</BODY>

</HTML>

Open in new window


And this is the error I get:

Fatal error: Call to a member function fetch_array() on a non-object in /homepages/35/d387195482/htdocs/herename/customerinfo.php on line 43
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 37798964
Lines 43-46
	while($row = $result->fetch_array(MYSQLI_ASSOC)) {
		print_r($row);
		echo '<br />';
	}

Open in new window

I am not sure this is all that is wrong, and I cannot test because I do not have your data base, but it seems like this is something worth trying.  Best, ~Ray
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

813 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

12 Experts available now in Live!

Get 1:1 Help Now