Solved

Help with PHP query

Posted on 2012-04-02
3
246 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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…
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…
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…

856 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