Hi, I don't usually develop for PHP or MySQL, but I am just doing the odd job for a friend.

I am having issues with a MySQL query though. A few days ago I must have done something to the code somewhere, and it is throwing up errors now. I have left the code and error message below, because I am not 100% sure on what is causing it.

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$server_time = date("H:i");
$day = date("N");

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_board = 10;
$pageNum_board = 0;
if (isset($_GET['pageNum_board'])) {
  $pageNum_board = $_GET['pageNum_board'];
}

$startRow_board = $pageNum_board * $maxRows_board;
$maxRows_board = 10;
$pageNum_board = 0;
if (isset($_GET['pageNum_board'])) {
  $pageNum_board = $_GET['pageNum_board'];
}
$startRow_board = $pageNum_board * $maxRows_board;

$area = mysql_real_escape_string($_GET['area']);

mysql_select_db($database_mystoptbr, $mystoptbr);
echo $query_board = "SELECT id, active, area, stop, service, `time`, destination, days FROM 'departures' WHERE `time` > '$server_time' AND active = 1 AND area = '$area' AND days = '$day' ORDER BY `time` ASC";
$query_limit_board = sprintf("%s LIMIT %d, %d", $query_board, $startRow_board, $maxRows_board);
$board = mysql_query($query_limit_board, $mystoptbr) or die(mysql_error());
$row_board = mysql_fetch_assoc($board);

if (isset($_GET['totalRows_board'])) {
  $totalRows_board = $_GET['totalRows_board'];
} else {
  $all_board = mysql_query($query_board);
  $totalRows_board = mysql_num_rows($all_board);
}
$totalPages_board = ceil($totalRows_board/$maxRows_board)-1;

$queryString_board = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_board") == false && 
        stristr($param, "totalRows_board") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_board = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_board = sprintf("&totalRows_board=%d%s", $totalRows_board, $queryString_board);
?>

The error is below (I have also added echo before the query):

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 ''departures' WHERE `time` > '00:38' AND active = 1 AND area = 'Paignton' AND day' at line 1

Thank you, any help will be much appreciated.

Update: This issue is now sorted. Sorry.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.