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

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.