用php编写的网页运行时出现如下错误:
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 'BY dateposted DESC' at line 1。
localhost blogtastic entries "InnoDB free: 4096 kB"
涉及到错误的表一结构如下
字段 类型 整理 属性 空 默认 额外 操作
id int(11) 否 无 AUTO_INCREMENT
cat_id tinyint(4) 否 无
dateposted datetime 否 无
subject varchar(100) utf8_unicode_ci 否 无
body text utf8_unicode_ci 否 无
表二结构如下: 字段 类型 整理 属性 空 默认 额外 操作
id int(11) 否 无 AUTO_INCREMENT
blog_id int(11) 否 无
dateposted datetime 否 无
name varchar(50) utf8_unicode_ci 否 无
comment text utf8_unicode_ci 否 无
从网上查资料说是sql语句的问题,但我使用phpmyadmin创建的数据库,记录也是在这里面添加的,不知道是哪里出错了,不知道怎么修改?
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 'BY dateposted DESC' at line 1。
localhost blogtastic entries "InnoDB free: 4096 kB"
涉及到错误的表一结构如下
字段 类型 整理 属性 空 默认 额外 操作
id int(11) 否 无 AUTO_INCREMENT
cat_id tinyint(4) 否 无
dateposted datetime 否 无
subject varchar(100) utf8_unicode_ci 否 无
body text utf8_unicode_ci 否 无
表二结构如下: 字段 类型 整理 属性 空 默认 额外 操作
id int(11) 否 无 AUTO_INCREMENT
blog_id int(11) 否 无
dateposted datetime 否 无
name varchar(50) utf8_unicode_ci 否 无
comment text utf8_unicode_ci 否 无
从网上查资料说是sql语句的问题,但我使用phpmyadmin创建的数据库,记录也是在这里面添加的,不知道是哪里出错了,不知道怎么修改?
$commsql="SELECT name FROM comments WHERE blog_id=".$row['id']."ORDER BY dateposted;";
$commresult=mysql_query($commsql);
if(!$commresult){
echo mysql_error();
exit;
}
$numrows_comm=mysql_num_rows($commresult); //有错误
本来是没有if语句的,提示出错在$commresult那一行,加上if语句之后就这样了
<?php
require("config.php");
if(isset($_GET['id'])==TRUE){
if(is_numeric($id)==FALSE){
$error=1;
}
if($error==1){
header("location:".$config_basedir."/viewcat.php");
}
else{
$validcat=$_GET['id'];
}
}
else{
$validcat=0;
}
$db=mysql_connect($dbhost,$dbuser,$dbpassword);
mysql_select_db($dbdatabase,$db);
$sql="SELECT * FROM categories";
$result=mysql_query($sql);
while($row=mysql_fetch_assoc($result)){
if($validcat=$row['id']){
echo "<strong>".$row['cat']."</strong><br />";
$entriessql="SELECT * FROM entries WHERE cat_id=".$validcat."ORDER BY dateposted DESC;";
$entriesres=mysql_query($entriessql);
if(!$entriesres){
echo mysql_error();
exit;
}
$numrows_entries=mysql_num_rows($entriesres);
echo "<ul>";
if($numrows_entries==0){
echo "<li>没有文章!</li>";
}
else{
while($entriesrow=mysql_fetch_assoc($entriesres)){
echo "<li>".date("D JS F Y g.iA".strtotime($entriesrow['dateposted']))."-<a href='viewentry.php?id=" .$entriesrow['id']."'>".$entriesrow['subject']."</a></li>";
}
}
echo "</ul>";
}
else{
echo "<a href='viewcat.php?id=".$row['id']."'>".$row['cat']."</a><br />";
}
}
require("footer.php");
?>
ORDER前面留一个空格,再试