I have an orders
table with order_id int(11)
as PK.
A user enters the order_id
and I pass it to MySql via
... WHERE order_id = ".db_input($order_id)."
The resulting SQL is as follows:
SELECT *
FROM oc_order
WHERE `order_id` = '16garbage'
It returns the record of order number 16!
WHY is it doing this? '16garbage' can NEVER be equal to integer 16!
How to fix this?
UPDATE #1: this has nothing to do with db_input. Forget that. It has everything to do with the EQUALITY order_id
= '16garbage'.
As Raymond Nijland said below:
"...query internally runs as select * from oc_order WHERE order_id= CAST('16garbage' AS UNSIGNED) because of the auto datatype casting."