当前位置:Gxlcms > PHP教程 > 这是哪里错了

这是哪里错了

时间:2021-07-01 10:21:17 帮助过:4人阅读

Query failed:SQLSTATE[42000]: Syntax error or access violation: 1064 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 'FROMmembersORDER BY username LIMIT 0,5' at line 1
找来找去都没发现错


回复讨论(解决方案)

FROMmembersORDER 这里没发现吗

把sql贴出来吧。

... FROM members ORDER BY username LIMIT 0,5

require_once("common.inc.php");
require_once("config.php");
require_once("Member.class.php");

$start = isset($_GET["start"])?(int)$_GET["start"]:0;
$order = isset($_GET["order"])?preg_replace("/[^a-zA-Z]/","",$_GET["order"]):"username";
list($members,$totalRows) = Member::getMembers($start,PAGE_SIZE,$order);
displayPageHeader("View book club members");
?>

Displaying members- $start+PAGE_SIZE,$totalRows)?>of










$rowCount = 0;
foreach($members as $member){
$rowCount++;
?>
>




}
?>
order=username">Username {?> order=firstname">First name {?> order=lastname">Last name {?>
getValueEncoded("id")?>">
getValueEncoded("username")?>
getValueEncoded("firstname")?> getValueEncoded("lastname")?>



0){?>
&
order=">Previous page


&order=">Next page



displayPageFooter();
?>


FROMmembersORDER 这里没发现吗
等级:Blank


#4 得分:0 回复于: 2013-11-15 15:40:40
require_once("common.inc.php");
require_once("config.php");
require_once("Member.class.php");

$start = isset($_GET["start"])?(int)$_GET["start"]:0;
$order = isset($_GET["order"])?preg_replace("/[^a-zA-Z]/","",$_GET["order"]):"username";
list($members,$totalRows) = Member::getMembers($start,PAGE_SIZE,$order);
displayPageHeader("View book club members");
?>

Displaying members- $start+PAGE_SIZE,$totalRows)?>of










$rowCount = 0;
foreach($members as $member){
$rowCount++;
?>
>




}
?>
order=username">Username {?> order=firstname">First name {?> order=lastname">Last name {?>
getValueEncoded("id")?>">
getValueEncoded("username")?>
getValueEncoded("firstname")?> getValueEncoded("lastname")?>



0){?>
&
order=">Previous page


&order=">Next page



displayPageFooter();
?>

... FROM members ORDER BY username LIMIT 0,5
等级:Blank


#4 得分:0 回复于: 2013-11-15 15:40:40
require_once("common.inc.php");
require_once("config.php");
require_once("Member.class.php");

$start = isset($_GET["start"])?(int)$_GET["start"]:0;
$order = isset($_GET["order"])?preg_replace("/[^a-zA-Z]/","",$_GET["order"]):"username";
list($members,$totalRows) = Member::getMembers($start,PAGE_SIZE,$order);
displayPageHeader("View book club members");
?>

Displaying members- $start+PAGE_SIZE,$totalRows)?>of










$rowCount = 0;
foreach($members as $member){
$rowCount++;
?>
>




}
?>
order=username">Username {?> order=firstname">First name {?> order=lastname">Last name {?>
getValueEncoded("id")?>">
getValueEncoded("username")?>
getValueEncoded("firstname")?> getValueEncoded("lastname")?>



0){?>
&
order=">Previous page


&order=">Next page



displayPageFooter();
?>

报错的代码没有贴出来,
list($members,$totalRows) = Member::getMembers($start,PAGE_SIZE,$order);

要看getMembers函数里面是如何写的。

FROMmembersORDER !!
难道是没有空格的原因 一坨拉出来了?

报错的代码没有贴出来,
list($members,$totalRows) = Member::getMembers($start,PAGE_SIZE,$order);

要看getMembers函数里面是如何写的。
require_once"DataObject.class.php";
class Member extends DataObject{
protected $data = array(
"id"=>"",
"username"=>"",
"password"=>"",
"firstName"=>"",
"lastName"=>"",
"joinDate"=>"",
"gender"=>"",
"favoriteGenre"=>"",
"emailAddress"=>"",
"otherInterests"=>""
);
private $_genres = array(
"crime"=>"Crime",
"horror"=>"Horror",
"thriller"=>"Thriller",
"romance"=>"Romance",
"sciFi"=>"Sci-Fi",
"adventure"=>"Adventure",
"nonFiction"=>"Non-Fiction"
);
public static function getMembers($startRow,$numRows,$order){
$conn = parent::connect();
$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM".TBL_MEMBERS."ORDER BY $order LIMIT :startRow,:numRows";

try{
$st = $conn->prepare($sql);
$st->bindValue(":startRow",$startRow,PDO::PARAM_INT);
$st->bindValue(":numRows",$numRows,PDO::PARAM_INT);
$st->execute();
$members = array();
foreach($st->fetchAll() as $row){
$members[] = new Member($row);
}
$st = $conn->query("SELECT found_rows() AS totalRows");
$row = $st->fetch();
parent::disconnect($conn);
return array($members,$row["totalRows"]);
}catch(PDOException $e){
parent::disconnect($conn);
die("Query failed:".$e->getMessage());
}
}

public static function getMember($id){
$conn = parent::connect();
$sql = "SELECT * FROM". TBL_MEMBERS. " WHERE id = :id";
try{
$st = $conn->prepare($sql);
$st->bindValue(":id",$id,PDO::PARAM_INT);
$st->execute();
$row = $st->fetch();
parent::disconnect($conn);
if($row) return new Member($row);
}catch(PDOException $e){
parent::disconnect($conn);
die("Query failed:".$e->getMessage());
}
}

public function getGenderString(){
return($this->data["gender"]=="f")?"Female":"Male";
}
public function getFavoriteGenreString(){
return ($this->_genres[$this->data["favouriteGenre"]]);
}
}
?>

$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM ".TBL_MEMBERS." ORDER BY $order LIMIT :startRow,:numRows"; //复制这句试试

$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM ".TBL_MEMBERS." ORDER BY $order LIMIT :startRow,:numRows"; //复制这句试试

还是报错了

前两个错误是说你的父类DataObject的connect() 和 disconnect() 不是静态方法,不能以静态方式调用。解决办法:在connect() 和 disconnect()前面加上 static 关键字。

第三个是说mydatabase.members 表不存在,检查一下吧。

前两个错误是说你的父类DataObject的connect() 和 disconnect() 不是静态方法,不能以静态方式调用。解决办法:在connect() 和 disconnect()前面加上 static 关键字。

第三个是说mydatabase.members 表不存在,检查一下吧。
你在那句sql语句里改了什么,好像看不到有改过的痕迹

from 后面和order 前面各加了一个空格

from 后面和order 前面各加了一个空格
这是什么错啊 为什么是这样改的

基本的sql语法,同学,该看书了。

人气教程排行