Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7016317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:46:08+00:00 2026-05-27T22:46:08+00:00

Well not being the best programmer in the land i thought i would ask

  • 0

Well not being the best programmer in the land i thought i would ask this question in the hope someone would spot the error or just tell me I am going the wrong way about it.

I have a Flash Builder web site that am trying to create a Search function to search my MYSQL database with and then return the results.

I have included the not null part just in case the user does not type any data in the relevant variable.

But I am getting this ERROR
Reason: Server error MySQL Error – 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘wells AND sex LIKE female’ at line 1 #0

HERE IS THE CODE

public function searchClients($fname, $lname, $country, $town, $sex) {

$SQLStatment = "SELECT id, fname, lname, sex, country, town, dateofbirth, monthofbirth, yearofbirth FROM $this->tablename";
$WhereClause = "";
$where =" Where ";

if($fname != "NULL") {
            $WhereClause.= 'Fname LIKE '.$fname;
}         

if($lname != "NULL") {
 if($WhereClause != "") 
 {  
            $WhereClause.= ' AND lname LIKE ' .$lname;
 }
 else
 {
        $WhereClause = 'lname LIKE ' .$lname;
 }
}

if($country != "NULL") {     
if($WhereClause != "") 
 {  
            $WhereClause.= ' AND country LIKE ' .$country;
 }
 else 
 {
        $WhereClause = 'country LIKE ' .$country;
 }
}

if($town != "NULL") {
 if($WhereClause != "") 
 {  
            $WhereClause.= ' AND town LIKE ' .$town;
 }
 else
 {
        $WhereClause = 'town LIKE ' .$town;
 }
}    

if($sex != "NULL") {
 if($WhereClause != "")
 {  
            $WhereClause.= ' AND sex LIKE ' .$sex;
 }
 else
 {
        $WhereClause = 'sex LIKE ' .$sex;
 }
}    
$SQLStatment.= $where;
$SQLStatment.= $WhereClause;

    $stmt = mysqli_prepare($this->connection, $SQLStatment);
    $this->throwExceptionOnError();

     mysqli_stmt_execute($stmt);
    $this->throwExceptionOnError();

    $rows = array();

    mysqli_stmt_bind_result($stmt, $row->ID, $row->fname, $row->lname,  $row->sex, $row->country, $row->town, $row->dateofbirth, $row->monthofbirth, $row->yearofbirth);

    while (mysqli_stmt_fetch($stmt)) {
      $row->fname = ucfirst(substr($row->fname,0,1));
      $row->lname = ucfirst($row->lname);
       $row->town = ucfirst($row->town);
      $row->lname = (($row->fname) . " " . ($row->lname));
      $row->yearofbirth = GetAge($row->dateofbirth. '-' .$row->monthofbirth. '-' .$row->yearofbirth);
      $row->Pic_loc = "";
      $row->Pic_loc= "IMAGES/".($row->ID)."/image01.jpg";
      $rows[] = $row;
      $row = new stdClass();
      mysqli_stmt_bind_result($stmt, $row->ID, $row->fname, $row->lname,  $row->sex, $row->country, $row->town, $row->dateofbirth, $row->monthofbirth, $row->yearofbirth);
    }

    mysqli_stmt_free_result($stmt);
    mysqli_close($this->connection);

    return $rows;
}

It looks good to me but does not work, any suggestions?
to pin point nearer in the code that its moaning is

if($town != "NULL") {
 if($WhereClause != "") 
 {  
            $WhereClause.= ' AND town LIKE ' .$town;
 }
 else
 {
        $WhereClause = 'town LIKE ' .$town;
 }
}    

if($sex != "NULL") {
 if($WhereClause != "")
 {  
            $WhereClause.= ' AND sex LIKE ' .$sex;
 }
 else
 {
        $WhereClause = 'sex LIKE ' .$sex;
 }
}    

just find it really odd that it does not moan about the other three if clauses but it does about the last two.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:46:08+00:00Added an answer on May 27, 2026 at 10:46 pm

    the where clauses should look like:

    $WhereClause .= ' AND sex LIKE "' . mysql_escape_string($sex).'"';
    

    You can use prepared statements / PDO to both simplify the code and protect the application from SQL injection

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm being handed some data which is not well defined and subject to change
My question is probably not well phrased and it's probably a dupe but here
I'm not the best with multi-threading, and this is a bit complicated, so hopefully
I have a problem I think would be well suited towards being made parallel,
I am not exactly sure what the best way to do this is. To
This is another question about well disposing objects from .NET. After having read a
I'm parsing a (not well formed) Apple Plist File with java. My Code looks
Suppose i have the code snippet as follows : ( clarification purpose/not well formed
http://www.programmersheaven.com/2/FAQ-ADONET Disconnected architecture is not well suited for desktop clients with multiple updates but
I need to use basic javascript here and I'm not well versed with it.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.