Mundo Posted March 8, 2009 Share Posted March 8, 2009 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"; ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 8, 2009 Share Posted March 8, 2009 re editted sorry m8. <?php $result = mysql_query(sprintf("SELECT * FROM customer WHERE '{$_GET['type']}' LIKE '%{$_GET['searchterm']}%'")); ?> Quote Link to comment Share on other sites More sharing options...
Mundo Posted March 8, 2009 Author Share Posted March 8, 2009 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? Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 8, 2009 Share Posted March 8, 2009 try my re-edited sql Quote Link to comment Share on other sites More sharing options...
Mundo Posted March 8, 2009 Author Share Posted March 8, 2009 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 Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 8, 2009 Share Posted March 8, 2009 try agin <?php $result = mysql_query("SELECT * FROM customer WHERE '{$_GET['type']}' LIKE '%{$_GET['searchterm']}%'"); ?> Quote Link to comment Share on other sites More sharing options...
Mundo Posted March 8, 2009 Author Share Posted March 8, 2009 try agin <?php $result = mysql_query("SELECT * FROM customer WHERE '{$_GET['type']}' LIKE '%{$_GET['searchterm']}%'"); ?> Nope, still finding no results even though I know there is... Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 8, 2009 Share Posted March 8, 2009 $row = mysql_fetch_array($result)or die(mysql_error()); and echo the sql out if it correct. are you sure that ?type=what_ever&searchterm=what_ever correctly url formatted for the get to work. Quote Link to comment Share on other sites More sharing options...
Mundo Posted March 8, 2009 Author Share Posted March 8, 2009 Even this won't work: $result = mysql_query("SELECT * FROM customer WHERE 'customer_lastname' LIKE 'Hodges'"); And I KNOW that is right. I copied it from phpMyAdmin and that found the results... Hmm Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 8, 2009 Share Posted March 8, 2009 if(mysql_num_rows($result) > 0) { to if(mysql_num_rows($row) > 0) { Quote Link to comment Share on other sites More sharing options...
Mundo Posted March 8, 2009 Author Share Posted March 8, 2009 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... Quote Link to comment Share on other sites More sharing options...
Mundo Posted March 8, 2009 Author Share Posted March 8, 2009 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? Quote Link to comment Share on other sites More sharing options...
Mundo Posted March 8, 2009 Author Share Posted March 8, 2009 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"? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.