wright67uk Posted January 13, 2011 Share Posted January 13, 2011 Hello! Im doing my very best to learn php. Im trying to create some php that will pull some values from mysql database which I have setup. If within my database i type the following sql statement; SELECT phone FROM treesurgeons WHERE EN ='YES' ORDER BY companyName LIMIT 3 Then i have three results returned. However my php file will only say; "Sorry your search "EN" returned no results". 'postcodestrip' is from a basic html form (on a different page). oes anybody hav any ideas where im going wrong? <html><body><?php $var = @$_GET['postcodestrip'] ; $trimmed = trim($var); $limit=3; if ($trimmed == "") {echo "<p>Please enter a search...postcode</p>"; exit;} if (!isset($var)) {echo "<p>We dont seem to have a postcode to go on!</p>"; exit;} mysql_connect("HOSTNAME HERE","USERNAME HERE","MYPASWORD"); mysql_select_db("MYDATABASE") or die("Unable to select database"); $query = "SELECT phone FROM treesurgeons WHERE %$trimmed% ='YES' ORDER BY companyName LIMIT 3"; $numresults=mysql_query($query); if ($numresults == 0) {echo "<h4>Results</h4>"; echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>";} ?></body></html> Quote Link to comment https://forums.phpfreaks.com/topic/224284-could-this-be-a-syntax-issue/ Share on other sites More sharing options...
trq Posted January 13, 2011 Share Posted January 13, 2011 Remove the wildcards % from around $trimmed. Quote Link to comment https://forums.phpfreaks.com/topic/224284-could-this-be-a-syntax-issue/#findComment-1158805 Share on other sites More sharing options...
ttocskcaj Posted January 13, 2011 Share Posted January 13, 2011 You don't need the curly braces {} if a block is one line. if ($trimmed == "") echo "<p>Please enter a search...postcode</p>"; exit; Should work. I'm not sure what you're trying to do here? Are you trying to return a phone number to match a post code? or something like that? How is your DB structured? Quote Link to comment https://forums.phpfreaks.com/topic/224284-could-this-be-a-syntax-issue/#findComment-1158810 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.