I have the following code in a PHP which works, but I suspect it susceptible to SQL injection. Am I right? The query is to a Firebird 2.1 database, not MySQL.
$timesheetBatchNo = '221706';
$query = "SELECT DATEWORKED, ORDERTYPE, REFERENCENUMBER, REFERENCEDESCRIPTION, TASKORSTEPNAME, HOURSWORKED, RECORDEDNOTES, ADDITIONALFIELD_1 as EU_REFERENCENUMBER, ADDITIONALFIELD_2 AS EU_TASKORSTEP, ADDITIONALFIELD_3 AS RDACTIVITY";
$query .= " FROM TIMESHEETLINES ";
$query .= " WHERE TIMESHEETBATCHNO=$timesheetBatchNo ";
I believe instead of including $employeename in the SQL string, I need to parse the variable into the query.
I understand I should be able to do this via:
ibase_bind_param($query , 1, $employeename); or
ibase_execute($query, $employeename); or
$stmt->bindValue(':empname', $employeename); but none of these are working right now.
Yes, you're correct. The code you provided is susceptible to SQL injection because it directly includes the $timesheetBatchNo variable in the SQL string without proper sanitization or parameter binding.
You should use parameterized queries or prepared statements.