Jump to content

Could this be a syntax issue?!?


wright67uk

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/224284-could-this-be-a-syntax-issue/
Share on other sites

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?

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.