Jump to content

[SOLVED] Help with Simple Search


Mundo

Recommended Posts

When I hit my submit problem, I get the following error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in K:\xampp\htdocs\clicker\customer.php on line 11

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in K:\xampp\htdocs\clicker\customer.php on line 13

 

I'm guessing its some sort of problem with my query...

 

 

Screenshot of problem: http://i44.tinypic.com/2q9w8x2.png

 

<?
include "tpl/header.tpl";
include "tpl/navigation_customer.tpl";

include "tpl/customersearch.tpl";

if($_GET['module'] == "search") {
if(isset($_GET['submitsearch'])) {

	$result = mysql_query(sprintf("SELECT * FROM customer WHERE '$_GET[type]' = '$_GET[searchterm]'"));
	$row = mysql_fetch_array($result);		

	if(mysql_num_rows($result) > 0) {
		echo "No results were found!";
		}
	else {
		echo $row['customer_id'] . "<br />";
		echo $row['customer_firstname'] . "<br />";
		echo $row['customer_lastname'] . "<br />";
		echo $row['customer_address1'] . "<br />";
		echo $row['customer_address2'] . "<br />";
		echo $row['customer_customerpostcode'] . "<br />";
		echo $row['customer_dob'] . "<br />";
		echo $row['customer_email'] . "<br />";
		echo $row['customer_tel'] . "<br />";
		}
	}
}

echo "<hr />";

echo "<h1>Add Customer</h1><p>Blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah </p>";

include "tpl/sidebar.tpl";
include "tpl/footer.tpl";
?>

Link to comment
https://forums.phpfreaks.com/topic/148508-solved-help-with-simple-search/
Share on other sites

LOL, OK, I solved that problem...

 

mysql_connect("localhost","root","");
mysql_select_db("clicker");

 

Now I feel stupid  ;)

 

But it still returns no results even if I know there is some. It doesn't return with "No results were found!" either... So it's obviously found a row of results... Any ideas?

re editted sorry mate.

<?php
$result = mysql_query(sprintf("SELECT * FROM customer WHERE '{$_GET['type']}' LIKE '%{$_GET['searchterm']}%'"));
?>

 

That gives me:

 

Warning: sprintf() [function.sprintf]: Too few arguments in K:\xampp\htdocs\clicker\customer.php on line 13

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in K:\xampp\htdocs\clicker\customer.php on line 14

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in K:\xampp\htdocs\clicker\customer.php on line 16

if(mysql_num_rows($result) > 0) {

 

to

 

if(mysql_num_rows($row) > 0) {

 

Yeh i already fixed that. I think I know the problem though.

 

This works:

 

$result = mysql_query("SELECT * FROM customer WHERE customer_lastname LIKE '$_GET[searchterm]'");

 

But when I change customer_lastname to '$_GET[type]' is when the problems start, i think it's something to do with the apostrophes...

I sussed it. I needed:

 

		$result = mysql_query("SELECT * FROM customer WHERE `$_GET[type]` LIKE '$_GET[searchterm]'");

 

Ok, one question though, your example included "%", what does that do?

 

Ah finds one or more characters. I see... Anyway I could get it to search for similar results? So if I searched for "smth" it would find "smith"?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.