Where is the error? 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 'at line 1
No error found
Reply to discussion (solution)
FROMmembersORDER is not found here
Paste the SQL statement.
... 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
>
Order = username "> Username {?> |
Order = firstname "> First name {?> |
Order = lastname "> Last name {?> |
$ RowCount = 0;Foreach ($ members as $ member ){$ RowCount ++;?>
GetValueEncoded ("id")?> "> GetValueEncoded ("username")?> |
GetValueEncoded ("firstname")?> |
GetValueEncoded ("lastname")?> |
}?>
0) {?>
&
Order = "> Previous page
& Amp; order = "> Next page
DisplayPageFooter ();
?>
FROMmembersORDER is not found here
Grade: Blank
#4 score: 0 Reply to: 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
>
Order = username "> Username {?> |
Order = firstname "> First name {?> |
Order = lastname "> Last name {?> |
$ RowCount = 0;Foreach ($ members as $ member ){$ RowCount ++;?>
GetValueEncoded ("id")?> "> GetValueEncoded ("username")?> |
GetValueEncoded ("firstname")?> |
GetValueEncoded ("lastname")?> |
}?>
0) {?>
&
Order = "> Previous page
& Amp; order = "> Next page
DisplayPageFooter ();
?>
... FROM members order by username LIMIT 0, 5
Grade: Blank
#4 score: 0 Reply to: 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
>
Order = username "> Username {?> |
Order = firstname "> First name {?> |
Order = lastname "> Last name {?> |
$ RowCount = 0;Foreach ($ members as $ member ){$ RowCount ++;?>
GetValueEncoded ("id")?> "> GetValueEncoded ("username")?> |
GetValueEncoded ("firstname")?> |
GetValueEncoded ("lastname")?> |
}?>
0) {?>
&
Order = "> Previous page
& Amp; order = "> Next page
DisplayPageFooter ();
?>
The error code is not posted,
List ($ members, $ totalRows) = Member: getMembers ($ start, PAGE_SIZE, $ order );
It depends on how the getMembers function is written.
FROMmembersORDER !!
Why is there no space?
The error code is not posted,
List ($ members, $ totalRows) = Member: getMembers ($ start, PAGE_SIZE, $ order );
It depends on how the getMembers function is written.
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"; // try copying this sentence
$ SQL = "SELECT SQL _CALC_FOUND_ROWS * FROM". TBL_MEMBERS. "ORDER BY $ order LIMIT: startRow,: numRows"; // try copying this sentence
Error reported
The first two errors indicate that the connect () and disconnect () methods of your parent class DataObject are not static methods and cannot be called in static mode. Solution: add the static keyword before connect () and disconnect.
The third is that the mydatabase. members table does not exist. check it.
The first two errors indicate that the connect () and disconnect () methods of your parent class DataObject are not static methods and cannot be called in static mode. Solution: add the static keyword before connect () and disconnect.
The third is that the mydatabase. members table does not exist. check it.
What have you changed in that SQL statement? it seems that there are no traces of modification.
A space is added before the from clause and the order clause.
A space is added before the from clause and the order clause.
What's wrong? why did this change?
It's time to read the basic SQL syntax.