Hi everyone,
This is a similar problem that I recently posted, but it is different. I am having issues with using values retrieved using $GET in SQL queries. I have a value in a url like this www.domain.com/update_record.php?isbn=123456789. I am trying to retrieve the isbn=123456789 from the URL using $GET. I set $isbn = to $_GET[isbn]. Then I try to call $isbn in the SQL query. I get a DB Error: syntax error. However, if I print the sql query it returns the correct query.
Here is my code:
$isbn = $_GET['isbn'];
$sql = "SELECT isbn, artist_name, album_title, date_format(release_date, \'%M %d, %Y\') as release_date, date_format(add_date, \'%M %d, %Y\') as add_date, description, price FROM lounge WHERE isbn = $isbn";
print $sql;
$rows = $db->query($sql);
print "<table>";
foreach($rows as $row) {
print "<tr><td>ISBN:</td><td>$rows[isbn]</td></tr>
<tr><td>Artist Name:</td><td>$rows[artist_name]</td></tr>
<tr><td>Album Title:</td><td>$rows[album_title]</td></tr>
<tr><td>Release Date:</td><td>$rows[release_date]</td></tr>
<tr><td>Add Date:</td><td>$rows[add_date]</td></tr>
<tr><td>Description:</td><td>$rows[description]</td></tr>
<tr><td>Price:</td><td>$rows[price]</td></tr></tr>";
}
?>