[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Whats wrong with my query?

Posted on 2011-05-02
3
Medium Priority
?
244 Views
Last Modified: 2012-05-11
Hi, its telling me that my query is failing though I cannot understand why.  Can anyone see whats wrong with it?

(I put it in my phpmyadmin and it works fine!)

http://auroriella.com/view_users.php

string(43) "SELECT * FROM users ORDER BY first_name ASC" Query failed:


function view_users() {
	$query = "SELECT * FROM users ";
	$query .= "ORDER BY first_name ASC";
	var_dump($query);
	$result = mysql_query($query, $conn);
	confirm_query($result);
$output = <<<HERE
<table border="1px" cellspacing="0" cellpadding="5px">
  <tr>
	<th>Username</th>
	<th>Name</th>
	<th>Address</th>
	<th>Phone</th>
	<th>Email</th>
	<th>Admin</th>
  </tr>
HERE;
	while($users = mysql_fetch_assoc($result)) {
		$output .= "<tr>";
		$output .= "<td>" . $users['username'] . "</td>";
		$output .= "<td>" . $users['first_name'] . " " . $users['first_name'] . "</td>";
		$output .= "<td>" . $users['address'] . "," . $users['city'] . "," . $users['state'] . "</td>";
		$output .= "<td>" . $users['phone'] . "</td>";
		$output .= "<td>" . $users['admin'] . "</td>";
		$output .= "</tr>";
	}
	$output .= "</table>"; 
	return $output;
}

Open in new window

0
Comment
Question by:FairyBusiness
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 35510003
try:

function view_users() {
global $conn;
      $query = "SELECT * FROM users ";
      $query .= "ORDER BY first_name ASC";
      var_dump($query);
      $result = mysql_query($query, $conn);
...
0
 

Author Closing Comment

by:FairyBusiness
ID: 35510011
Thanks again!
0
 
LVL 82

Expert Comment

by:hielo
ID: 35510012
and make sure you are connecting to the DB BEFORE you call the function:
$conn=mysql_connect('...','...','...');
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month19 days, 5 hours left to enroll

834 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