Forum Moderators: coopster
$query = "SELECT * FROM books WHERE user_id =($_SESSION['user_id'])";
$result = mysql_query ($query); // Run the query.
while ($row = mysql_fetch_array($result)) {
$book_id = $row['book_id'];
$user_id = $row['user_id'];
$title = stripslashes($row['title'])
$display_block .= "<p><strong>$title</strong>
</p>";
}
This part returns the error:
WHERE user_id =($_SESSION['user_id']
I have two tables. One that registers users and one that records books by the users. I can see that the registration script for the users work. The table for the books records a number for each book and than the number for the user who inputted the book title. But I can't figure out how to retrieve the book titles so that each users can see his book list when he logs in.
Any suggestions are greatly appreciated.
I am assuming that user id has been validated as an integer - if not, you'll need to do:
$query='SELECT * FROM books WHERE user_id=\'' . mysql_real_escape_string($_SESSION['user_id']) . '\'';
Also, rather than SELECT *, select only the columns you need - SELECT * is almost always the sloppy alternative.
Also change
$query = "SELECT * FROM books WHERE user_id =($_SESSION['user_id'])";
TO
$query = "SELECT * FROM books WHERE user_id =". $_SESSION['user_id'] ."";
OR
$query = "SELECT * FROM books WHERE user_id ='". $_SESSION[user_id] ."'";
And it should work fine.
Habtom