Solved

Help with PHP query

Posted on 2012-04-02
3
249 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
[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
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 110

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

Industry Leaders: 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

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…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
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 …

623 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