php - 错误 : You have an error in your SQL syntax near '' at line 1

标签 php mysql

我一直收到此错误...但我看不到任何不合适的语法...有什么想法吗? 这是我的 PHP 代码。我知道我的其他页面是正确的,因为我可以毫无问题地运行代码的所有其他部分。

<?php 

// this connects To database
$hostname="";    
$username="";   
$password="";    
$dbname="";     

mysql_connect($hostname,$username,$password) OR DIE ("Connection Failed");
mysql_select_db($dbname);


$action = $_REQUEST["action"];
if ($action == 'a') {
$custFirst = null;
$custLast = null;
$custAddress = null;
$custCity = null;   
$custState = null;
$custZip = null;
$custEmail = null;
$custPhone = null;
 } else {
$id = $_REQUEST["id"];
    $query = "select * from custTab where custNo = $id";
    $result = mysql_query($query) 
        or die(mysql_error());
    $row = mysql_fetch_array($result);
    $custFirst = $row['custFirst'];  
    $custLast = $row['custLast'];  
    $custAddress = $row['custAddress'];  
    $custCity = $row['custCity'];
    $custState = $row['custState'];
    $custZip = $row['custZip'];
    $custEmail = $row['custEmail'];
    $custPhone = $row['custPhone'];
} // end if

?>

最佳答案

尝试在 $id 周围加上 引号

$query = "select * from custTab where custNo = '$id'";

关于php - 错误 : You have an error in your SQL syntax near '' at line 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13825146/

相关文章:

php - WordPress 有时很慢,有时又很快

php - 使用 php ajax 检查用户名和密码

mysql - 按星期分组mysql

Mysql Insert Where Column 类似于通配符查询

php 使用 switch 不间断;

php - AdWords 严重误报点击次数 - 第 3 方跟踪页面丢失了 50% 的点击次数

php - 根据最大日期过滤结果

php - php中csv文件中的SQL Select语句

php - 我 honeSTLy 不知道如何制定这个按引用传递的难题

mysql - mysql更新过程中遇到问题