MySQL Error: You have an error in your SQL syntax;

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ebflute
    New Member
    • Dec 2010
    • 3

    MySQL Error: You have an error in your SQL syntax;

    What is wrong with my SQL statement? I moved this application from a PHP4 server to a PHP5 server with a higher version of MySQL. It was working on the old server but now I am getting an error in the syntax.

    Code:
    MySQL 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 near '' at line 24
    Code:
    SQL Statement: SELECT * FROM agency WHERE date_time LIKE '%%' AND city LIKE '%%' AND county LIKE '%%' AND impact_agenda LIKE '%%' AND agency_category LIKE '%%' AND (org_name LIKE '%%' OR address LIKE '%%' OR city LIKE '%%' OR state LIKE '%%' OR mail_address LIKE '%%' OR mail_city LIKE '%%' OR mail_state LIKE '%%' OR homepage LIKE '%%' OR name_on_501 LIKE '%%' OR org_phone LIKE '%%' OR contact_phone LIKE '%%' OR fax LIKE '%%' OR org_description LIKE '%%' OR first_name LIKE '%%' OR last_name LIKE '%%' OR email LIKE '%%' OR date_time LIKE '%%' OR impact_agenda LIKE '%%' OR agency_category LIKE '%%') ORDER BY id DESC LIMIT 0,
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    This isn't a PHP question, but a MySQL one. I'll move this thread over there.

    Comment

    • JKing
      Recognized Expert Top Contributor
      • Jun 2007
      • 1206

      #3
      Can you provide the actual code snippet?

      Comment

      • ebflute
        New Member
        • Dec 2010
        • 3

        #4
        Is this the code that will help determine the problem?

        Forgive me if this isn't what you are asking for as I am not an expert in MySQL. I went to the page in question and found this relevant PHP code:

        Code:
        <?php
        			// Get filters
        			$year = (isset($_SESSION['year'])) ? $_SESSION['year'] : '';
        			$city = (isset($_SESSION['city'])) ? $_SESSION['city'] : '';
        			$county = (isset($_SESSION['county'])) ? $_SESSION['county'] : '';
        			$impact_agenda = (isset($_SESSION['impact_agenda'])) ? $_SESSION['impact_agenda'] : '';
        			$agency_category = (isset($_SESSION['agency_category'])) ? $_SESSION['agency_category'] : '';
        			$search = (isset($_SESSION['search'])) ? preg_replace('/[^a-z 0-9_-]/i', '', $db->escape($_SESSION['search'])) : '';
        			$sort = (isset($_SESSION['sort'])) ? $_SESSION['sort'] : '';
        			
        			$where = "date_time LIKE '%$year%' AND
        					  city LIKE '%$city%' AND
        					  county LIKE '%$county%' AND
        					  impact_agenda LIKE '%$impact_agenda%' AND
        					  agency_category LIKE '%$agency_category%' AND
        					  (org_name LIKE '%$search%' OR
        					   address LIKE '%$search%' OR
        					   city LIKE '%$search%' OR
        					   state LIKE '%$search%' OR
        					   mail_address LIKE '%$search%' OR
        					   mail_city LIKE '%$search%' OR
        					   mail_state LIKE '%$search%' OR
        					   homepage LIKE '%$search%' OR
        					   name_on_501 LIKE '%$search%' OR
        					   org_phone LIKE '%$search%' OR
        					   contact_phone LIKE '%$search%' OR
        					   fax LIKE '%$search%' OR
        					   org_description LIKE '%$search%' OR
        					   first_name LIKE '%$search%' OR
        					   last_name LIKE '%$search%' OR
        					   email LIKE '%$search%' OR
        					   date_time LIKE '%$search%' OR
        					   impact_agenda LIKE '%$search%' OR
        					   agency_category LIKE '%$search%')";
        					   
        			$org_name_th = ($sort == 'org_name ASC') ? 'org_name DESC' : 'org_name ASC';
        			$org_name_img = 'bg';
        			if ($sort == 'org_name ASC') $org_name_img = 'asc';
        			if ($sort == 'org_name DESC') $org_name_img = 'desc';
        			$impact_th = ($sort == 'impact_agenda ASC') ? 'impact_agenda DESC' : 'impact_agenda ASC';
        			$impact_img = 'bg';
        			if ($sort == 'impact_agenda ASC') $impact_img = 'asc';
        			if ($sort == 'impact_agenda DESC') $impact_img = 'desc';
        			$agency_th = ($sort == 'agency_category ASC') ? 'agency_category DESC' : 'agency_category ASC';
        			$agency_img = 'bg';
        			if ($sort == 'agency_category ASC') $agency_img = 'asc';
        			if ($sort == 'agency_category DESC') $agency_img = 'desc';
        			$date_th = ($sort == 'id ASC') ? 'id DESC' : 'id ASC';
        			$date_img = 'bg';
        			if ($sort == 'id ASC') $date_img = 'asc';
        			if ($sort == 'id DESC') $date_img = 'desc';
        			
        			$count = count($db->find_all('', $where));
        			if ($per_page == 'All')
        				$per_page = $count;
        			$page = (isset($_SESSION['page'])) ? $_SESSION['page'] : 1;
        			$offset = ($page - 1) * $per_page;
        			$p = new pagination;
        			$p->items($count);
        			$p->limit($per_page);
        			$p->adjacents(4);
        			$p->urlFriendly();
        			$p->target('manage/page/%/');
        			$p->currentPage($page);
        			
        			$_checked = ' checked="checked"';
        			$_selected = ' selected="selected"';
        			?>

        Comment

        • ebflute
          New Member
          • Dec 2010
          • 3

          #5
          There was an error in the way the cookie was being set and the problem has been fixed in the application--I had to hire an experienced developer. Thank you for attempting to help me. I appreciate it.

          Comment

          Working...