Jump to content

Search script returns error


laPistola

Recommended Posts

Hello

 

i have writen a script that handles $_POST vars to return a set of data form a search form but i get this 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 'jobs WHERE (location = 'East Midlands') AND (salary BETWEEN '10.000' AND '20.000' at line 1

 

The code is:

 

<?php
if ((isset($_POST)) && (!empty($_POST['location']))) {
mysql_select_db($database_qwork, $qwork);
// Find location or area search
$loc_sql = "SELECT sid FROM cities WHERE cid = '".$_POST['location']."'";
$loc_query = mysql_query($loc_sql, $qwork) or die(mysql_error());
$loc = mysql_fetch_assoc($loc_query);

// build the sql
$sVals = explode('-',$_POST['salary']);
$s_sql = "SELECT title, jid, location, area, salary, description FORM jobs WHERE ";
if ($loc['sid']==1) {
	$s_sql .= "(area = '".$_POST['location']."')";
} else {
	$s_sql .= "(location = '".$_POST['location']."')";
}
if ($_POST['salary']!='All') {
	$s_sql .= " AND (salary BETWEEN '".$sVals[0]."' AND '".$sVals[1]."')";
}
if (!empty($_POST['keyword'])) {
	$s_sql.= " AND (title = '%".$_POST['keyword']."%')";
}
$s_sql .= " ORDER BY salary DESC";
	// work out number of pages
	$s_pages_query = mysql_query($s_sql, $qwork) or die(mysql_error());
	$s_pages_num = mysql_num_rows($s_pages_query);
	$s_pages = ceil($s_rows_num / 10);
	$s_page = 0;
	if (isset($_POST['page'])) {
		$s_page = $_POST['page'];
	}
	$s_page = ceil($s_page * 10);
// query DB
$s_sql .= " LIMIT ".$s_page.", 10";
$s_query = mysql_query($s_sql, $qwork) or die(mysql_error());
$s_rows = mysql_fetch_assoc($s_query);
}
?>

 

The form posts these vars

 

$_POST['keyword'] = which is blank in this query

$_POST['salary'] = 10.000 - 20.000;

$_POST['location'] = East Midlands;

 

Thank you for any help

 

Link to comment
https://forums.phpfreaks.com/topic/193203-search-script-returns-error/
Share on other sites

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.