SitePoint Sponsor |
|
User Tag List
Results 1 to 9 of 9
Thread: mySQL errors
-
Sep 8, 2005, 11:55 #1
- Join Date
- Mar 2005
- Posts
- 10
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
mySQL errors
I've got no clue why this piece of code is generating an error. Everything else on the site works fine.
Hope you all can help, and thanks in advance.
Code:<? ###Get database functions and connect to DB require("admin/sub.php"); db_connect(); ###Query the database and store retrieved data in $comment $query = "SELECT * FROM data WHERE id = '$id' AND approved = '1'"; $result = mysql_query($query); $comment = mysql_fetch_array($result); ###Assign variables from data retrieved $id = $comment["id"]; $title = $comment["title"]; $text = $comment["text"]; ###Display the data if($id) { echo "<b>$title</b><br /><br />"; echo "$text<br /><br />"; } else { echo "Error retrieving record<br /><br />"; } ?>
-
Sep 8, 2005, 11:57 #2
- Join Date
- Jul 2004
- Location
- The Caribbean
- Posts
- 267
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
What error is it outputting?
-
Sep 8, 2005, 12:01 #3
- Join Date
- Aug 2003
- Location
- Manchester, UK
- Posts
- 4,007
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
$query = "SELECT * FROM data WHERE id = '$id' AND ...
-
Sep 8, 2005, 12:07 #4
- Join Date
- Mar 2005
- Location
- Sunny Florida
- Posts
- 145
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The error is probably coming from using the word "data", which is a reserved MySQL word.
-
Sep 8, 2005, 12:09 #5
- Join Date
- Mar 2005
- Location
- Sunny Florida
- Posts
- 145
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Sorry for the redundant response. I must have been reading while markl999 was posting.
-
Sep 8, 2005, 16:05 #6
- Join Date
- Mar 2005
- Posts
- 10
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It doesn't generate any errors, but the strange thing is the following code segment works perfectly.
Code:###Display all approved comments $query = "SELECT * FROM data WHERE approved='1' ORDER BY `id` DESC"; $result = mysql_query($query); ###Display the unapproved comments while($comments = mysql_fetch_array($result)) { $id = $comments["id"]; $title = $comments["title"]; echo "...<a href=\"view.php?id=$id\" target=\"main\">$title</a>...<br /><br />"; }
-
Sep 8, 2005, 16:34 #7
- Join Date
- Jul 2004
- Location
- The Caribbean
- Posts
- 267
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
If it is not displaying an error, then what is wrong?
Are you sure you have it setup to display errors to the screen? If not, you may need to either enable error displays or check your logs for the error message.
-
Sep 8, 2005, 22:11 #8
- Join Date
- Mar 2005
- Posts
- 10
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The problem with that first bit is that it isn't getting any data from the database. I put in some mysql_error()'s, and still nothing showed up. Also, when I try to change data to 'data', I get some syntax errors.
Here is the error I mentioned:
Code:A fatal MySQL error occured. Query: SELECT * FROM 'data' WHERE id = '' AND approved = '1' Error: (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 ''data' WHERE id = '' AND approved = '1'' at line 1
-
Sep 8, 2005, 22:13 #9
- Join Date
- Aug 2003
- Location
- Manchester, UK
- Posts
- 4,007
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Also, when I try to change data to 'data', I get some syntax errors.
Bookmarks