下面是代码,但我收到此错误
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 3
任何帮助将不胜感激。
<?php
include("../includes/conn.php");
$sql = "SELECT *
FROM `t_maincontent`
where uid_page =". $_GET['page'] ;
$results = mysql_query($sql, $conn) or die(mysql_error());
$content = mysql_fetch_assoc($results);
//print $content['nv_content']."¬".$content['nv_title']."¬".$content['nv_meta'];
?>
最佳答案
请阅读有关从 PHP 进行数据库查询的基础知识。
您应该检查是否 $_GET['page']
通过 isset( $_GET['page'] );
存在仅发送查询(如果存在)。
include( '../includes/conn.php' );
if( isset( $_GET['page'] ) )
{
/* cast to int would be enough to cancel SQL injection attacks */
$sql = 'SELECT * FROM t_maincontent WHERE uid_page = ' . (int) $_GET['page'] ;
$results = mysql_query($sql, $conn) or die(mysql_error());
$content = mysql_fetch_assoc($results);
}
关于php - SQL 查询的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16213710/