searching an SQL database with a form

Nope, its still not liking anything on

Parse error: parse error, unexpected T_VARIABLE in /home/caldico/public_html/fcv/database/search.php on line 32



$result = mysql_query($sql);

that line, cant think what else it could be, iv tried many different combinations but nothing seems to be changing
 
Code:
$sql = "SELECT * FROM $searchTable WHERE MATCH (Fields) AGAINST ('$userQuery');"
To:
Code:
$sql = "SELECT * FROM $searchTable WHERE MATCH (Fields) AGAINST ('$userQuery')";

Annoying little bugger :)
 
Beansprout said:
Code:
$sql = "SELECT * FROM $searchTable WHERE MATCH (Fields) AGAINST ('$userQuery');"
To:
Code:
$sql = "SELECT * FROM $searchTable WHERE MATCH (Fields) AGAINST ('$userQuery')";

Annoying little bugger :)


Oh well, I tried :( :o
 
sorry to be a pain but there is one last problem i cant work out with the last while statement

Code:
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

function remove_magic_quotes($array) {
	foreach ($array as $k => $v) {
		if (is_array($v)) {
			$array[$k] = remove_magic_quotes($v);
		} else {
			$array[$k] = stripslashes($v);
		}
	}
	return $array;
}
if (get_magic_quotes_gpc()) {
	$_GET	= remove_magic_quotes($_GET);
	$_POST   = remove_magic_quotes($_POST);
	$_COOKIE = remove_magic_quotes($_COOKIE);
}

$input = strip_tags($_POST['userQuery']);
$searchTable = $_POST['select'];


$sql = "SELECT * FROM $searchTable WHERE MATCH (Fields) AGAINST ('$userQuery')";

$result = mysql_query($sql);

[b]while ($field = mysql_fetch_array($result))
{
	$searchResults = $field['FieldName'];
	
	echo $searchResults;
}
[/b]




?>

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/caldico/public_html/fcv/database/search.php on line 34
 
I'd suggest you try this:

Code:
$check = mysql_fetch_array($result);

while ($field == $check)
{
	$searchResults = $field['FieldName'];
	
	echo $searchResults;
}

instead of:

Code:
while ($field = mysql_fetch_array($result))
{
	$searchResults = $field['FieldName'];
	
	echo $searchResults;
}

:)
 
[Sniper][Wolf] said:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/caldico/public_html/fcv/database/search.php on line 34

Probably, (emphasis on probably) means your query failed and there isn't a valid result set to process.

Code:
$input = strip_tags($_POST['userQuery']);
$searchTable = $_POST['select'];


$sql = "SELECT * FROM $searchTable WHERE MATCH (Fields) AGAINST ('$userQuery')";

Just a quick scan through your code and I wasn't sure where $userQuery came from? Also, please escape your data properly.

Echo $sql and chuck it through phpMyAdmin or whatever, chances are you'll get a more sensible error message.

Trigger said:
I'd suggest you try this:

I don't think that will help...
 
Code:
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

function remove_magic_quotes($array) {
	foreach ($array as $k => $v) {
		if (is_array($v)) {
			$array[$k] = remove_magic_quotes($v);
		} else {
			$array[$k] = stripslashes($v);
		}
	}
	return $array;
}
if (get_magic_quotes_gpc()) {
	$_GET	= remove_magic_quotes($_GET);
	$_POST   = remove_magic_quotes($_POST);
	$_COOKIE = remove_magic_quotes($_COOKIE);
}

$input = strip_tags($_POST['userQuery']);
$searchTable = $_POST['select'];


$sql = "SELECT * FROM $searchTable WHERE MATCH (catagory, title) AGAINST ('$userQuery')";

$result = mysql_query($sql);

while ($field = mysql_fetch_array($result))
{
	$searchResults = $field['FieldName'];
	
	echo $searchResults;
	echo $sql;
}



?>

Its not returning any results as i have tried a number of different combo's. it dont like the while loop at the end, iv tried the $check alternative code that someone posted, it timed out.

Code:
while ($field = mysql_fetch_array($result))
{
	$searchResults = $field['FieldName'];
	
	echo $searchResults;
	echo $sql;
}

does the $field have to be replaced by a field name? changing $field in the loop and also change ['fieldName'] to an actual field name?
 
Last edited:
Back
Top Bottom