0
<?php
    include("login.php");
    $befehl = "SELECT * FROM produkte WHERE produkte.kategorie = BeliebteGerichte";
    
    foreach($pdo->query($befehl) as $row)
    {
    echo "
    <div class=angI>
        <div class=angF>
            <div id=t1>".$row['gericht']."</div>
            <div id=t2>".$row['erl']."</div>
            <div id=t3>".$row['wahl']."</div>
            <div id=t4>".$row['preis']."€</div>
        </div>
    </div>
    ";
    }
?>

My goal is to only display the dishes that have the text "BeliebteGerichte" in their kategorie column from my database. Maybe I made an obvious mistake but I have no idea about PHP.

Here is the error message I got:

Fatal error : Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'BeliebteGerichte' in 'where clause' in /users/christian313438/www/greeky/index.php:42 Stack trace: #0 /users/christian313438/www/greeky/index.php(42): PDO->query('SELECT * FROM p...') #1 {main} thrown in /users/christian313438/www/greeky/index.php on line 42

ad absurdum
  • 19,498
  • 5
  • 37
  • 60

3 Answers3

0

You are not assigning the string for search in the proper way . and the db engine assunme is a column anem

you need quotes around your string

for find the rows with a string try

 "SELECT * FROM produkte 
 WHERE produkte.kategorie like concat('%', 'BeliebteGerichte', '%')";

and for search for a substring you should use like operator and wildchar

ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
0

Welcome to SA. In your SQL query, you must use quotes around the string you are trying to match. For most SQL databases, they should be double quotes. So switch your PHP code to use single quotes and then like this: $befehl = 'SELECT * FROM produkte WHERE produkte.kategorie = "BeliebteGerichte"';

You will aslo need to clean up your HTML the same way to put quotes around the atttributes like: class="angF"

bitfiddler
  • 2,095
  • 1
  • 12
  • 11
0

you need to use 'BeliebteGerichte', I suggest working with PDO and Prepared Statements for a better and safer database connection.

also, check your column names and you better use _ than . in column names.