Whats wrong with my query?

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

FairyBusinessAsked:
Who is Participating?
 
hieloConnect With a Mentor Commented:
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
 
FairyBusinessAuthor Commented:
Thanks again!
0
 
hieloCommented:
and make sure you are connecting to the DB BEFORE you call the function:
$conn=mysql_connect('...','...','...');
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.