Jump to content

Unknown column in where clause and how to fix it


Revolutsio
Go to solution Solved by Barand,

Recommended Posts

I have made a database with my game collection.

I have got an index page with all games on and made a dynamic link to take me to the 'details.page' which gets all the information from that particular game that clicked on and then it gets all the information into boxes and I have made a link for the year of release for the game and when I click this it shows all the games from that year (I added the year to the database in varchar in the format 1999). and then I tried to move on the next link which is Genre and i did the same in the database entered it as varchar, so for example 'Shooter' but when I click on this link and use the same code as I did with the year page I get an error 'Unknown column 'Shooter' in 'where clause'

This is the link.

<a class='knil' href='genre.php?id=<?php echo $game['genre']; ?>'>

So on my genre page I have used at the top of the page.

<?php
include 'includes/config2.php';
$id = $_GET['id'];

When I echo this out I get the right answer. But when I try to get all the games that have 'Shooter'  in the genre column I get the error from above by using the following

$sql = "SELECT * FROM games WHERE genre = $id";
                $res = $db->query($sql) or die($db->error);
                while ($row = $res->fetch_assoc()) {
               //      echo $row['game'];
                    echo "<div class='picture bottom_margin'><img class='img' src='images/" . $row['image_name'] ."'>
                   <div class='top-margin'></div>
                   <div class='text text-shadow box-shadow bottom_margin text_center'>
                   <a class='knil' href='details.php?id={$row['id']}'</a>{$row['game']}</a>
                             {$row['id']}  
                   </div></a>
                   </div>
                   ";            
                } 

In the $sql line if i change the $id to 'Shooter' I get all the games but would like to be able to get link I clicked.

 

I know some of this code may not be the best, but this is a personal project and will not be going on the internet, Just trying to learn as I go along.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.