Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Help with PHP query

Posted on 2012-04-02
3
Medium Priority
?
252 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 111

Accepted Solution

by:
Ray Paseur earned 2000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
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.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

927 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