0

我使用 Dreamweaver 创建了一个基本的 mysql 查询(我的 php 和 mysql 知识非常有限):

这是代码:

<?php require_once('../Connections/ahbvc.php'); ?>
<?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;
}
}

mysql_select_db($database_ahbvc, $ahbvc);
$query_Recordset1 = "SELECT saida, DataRegisto, VIATURA, KMSAIDA, codigo, MORADA,    OpServiço FROM registo WHERE HORAENTRADA IS NULL ORDER BY saida";
$Recordset1 = mysql_query($query_Recordset1, $ahbvc) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
<?php do { ?>
<?php echo $row_Recordset1['']; ?>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

但是当我尝试加载页面时,我得到了这个错误:

您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“§o FROM registo WHERE HORAENTRADA IS NULL ORDER BY saida”附近使用正确的语法

可以请人帮助我吗?我已经搜索了每一段代码,但我找不到错误。

谢!

4

1 回答 1

0

你的问题是

“运营服务”

表中的字段名,您可以尝试使用反引号 `OpServiço` 转义表名,但一般建议仅使用小写字符abcdefghijklmnopqrstuvxyz和下划线 _ 用于数据库、表和字段名

于 2013-10-17T21:21:59.827 回答