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
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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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"?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.