Page 1 of 1

help please need simpl equeryy trouble shoot

Posted: Sat Jun 15, 2013 4:27 pm
by kratos-2012
This is a simple query question. This code gives me this error: "SELECT command denied to user ''@'localhost' for table 'some_tbl'"
I'm creating a simple search by first name. the field is indexed as FULLTEXT.

I want to be able to type in a name in the search box and have it match the input name and display results with only those names.
I'm learning php so this is a student question.
Thanks!

Here is the code:

Code: Select all

<?php include('connectdb.php');?>

<?php

// force script errors and warnings to show during production opnly
error_reporting(E_ALL);
ini_set('display_errors', '1');

// initialize the searh output variable
$search_output="";

if(isset($_POST['searchQuery']) && $_POST ['searchQuery'] !=""){
	
	// filter the search uqery user input
	$searchQuery = preg_replace('#[^a-z 0-9?]#i', '', $_POST['searchQuery']);

$sqlCommand = "(SELECT filedName AS title FROM some_tbl WHERE firstName LIKE '%$searchQuery%') UNION (SELECT filedName AS title FROM some_tbl WHERE firstName LIKE '%$searchQuery%')";

$query = mysql_query($sqlCommand) or die(mysql_error());
$count = mysql_num_rows($query);
if($count > 1){
	$search_output .= "$count results for $searchQuery!  $sqlCommand";
	while ($row = mysql_fetch_array($query)){
		$location = $row['firstName'];
		$search_output .= "Results: $location";
		}
	} else {
		$search_output = "no Results Found for $searchQuery!  $sqlCommand";
		}
}
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<strong>Search For:</strong> <br><br>
<input name="searchQuery" type="text" size="80" maxlength="88" value="City, State" class="search-input">
<input type="submit" value="Search">
</form>
It's not a connection error the connectdb.php works fine and I have other data that is queried from the same table. I'm wondering if my sql command is wrong.

Re: help please need simpl equeryy trouble shoot

Posted: Mon Jun 17, 2013 2:30 pm
by requinix
Either it's a connection error, which you're sure it's not, or the user you're connecting as doesn't have the right permissions on that server/database/table. Unless you're using the wrong information in your connectdb.php, it's not a code problem.