Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jan 2008
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post

    Php Error advice

    Im using a script to carryout a search on a mysql database and im getting the following error:

    "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use"

    Can anyone provide some info on this, is this something to do with the sql query i am using? Any advice would be must appreciated.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Post your query and the full error.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Jan 2008
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post
    Quote Originally Posted by abduraooft View Post
    Post your query and the full error.
    The full query is:

    PHP Code:
    <?php 
    include("database.php"); 

    $sql "SELECT * FROM job"
    $jobcat mysql_real_escape_string(trim($_POST['jobcategory'])); 
    $jobloc mysql_real_escape_string(trim($_POST['joblocation']));
     
    if (
    $jobcat != '' && $jobloc != '') { 
      
    $sql .= " WHERE jobcategory LIKE '$jobcat%' AND joblocation '%$jobloc%'"

    else if (
    $jobcat != '' && $jobloc == '') { 
      
    $sql .= " WHERE jobcategory LIKE '%$jobcat%'"

    else if (
    $jobloc != '' && $jobcat == '') { 
      
    $sql .= " WHERE joblocation LIKE '%$jobloc%'"


    $query mysql_query($sql) or die(mysql_error()); 

    if(
    mysql_num_rows($query) > 0

    while (
    $job mysql_fetch_array($query)) 

        
    $jobtitle=$job["jobtitle"];  
        
    $jobcategory=$job["jobcategory"];  
       
    ?>

    The error is:

    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 ''%Co.Antrim%'' at line 1

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    $sql .= " WHERE jobcategory LIKE '$jobcat&#37;' AND joblocation '%$jobloc%'";
    You missed the LIKE, the above should be
    Code:
    $sql .= " WHERE jobcategory LIKE '$jobcat%' AND joblocation LIKE '%$jobloc%'";
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    probably missing a 'like' in first if:
    PHP Code:
      $sql .= " WHERE jobcategory LIKE '$jobcat%' AND joblocation LIKE '%$jobloc%'"
    try to see if work. When you have this message you must look in the query where it point and before it, is about syntax:
    Code:
    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 ''%Co.Antrim%'' at line 1
    Edit:
    sorry abduraooft, I don't know about your post, edit process,


    best regards
    Last edited by oesxyl; 03-09-2008 at 03:59 PM.

  • #6
    Regular Coder
    Join Date
    Jan 2008
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post
    Quote Originally Posted by abduraooft View Post
    You missed the LIKE, the above should be
    Code:
    $sql .= " WHERE jobcategory LIKE '$jobcat%' AND joblocation LIKE '%$jobloc%'";
    Hey thanks for that, that worked fine.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •