L
L
LenaOlegovna2021-05-07 21:26:11
PHP
LenaOlegovna, 2021-05-07 21:26:11

Why is WHERE selection not working in SQL query?

I’m going crazy, I don’t understand why the WHERE selection in the SQL query does not work, help me find the error, it displays all records from the table at my request

$cat = intval($_GET["cat"]);
$sql = "SELECT * FROM tour WHERE `category` = $cat ";
$query = $pdo->query($sql); 
$tours = $query->fetchAll(PDO::FETCH_ASSOC);


Thanks in advance for any hint

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2021-05-07
@ThunderCat

first hint is to use prepared expressions
second hint is to display your query, copy paste into sql console / phpmyadmin and execute.

retrieves all records from a table
I can assume that this field is not a unique value and it's not surprising that you get ALL records where category = some number.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question