Solved

Help with PHP query

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

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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

20 Experts available now in Live!

Get 1:1 Help Now