Took Zoxor Took Zoxor - 8 months ago 24
PHP Question

php mysqli syntax for mixing variable with text in a field

hi and thank you in advance for any help you can give!

i'm iffy on syntax with variables in queries.

i have a database table with a column called 'iltr' and a column called 'refline'.

the 'refline' column is filled with text data like this: '1LINE1' '1LINE2' '1LINE3' '2LINE1' '2LINE2' '2LINE3' etc etc etc.

i want to use a variable that relates to the first digit of the data in the 'refline' column to update another column.

in the example below i'm trying to set 'iltr'= 'Y' where 'refline' is '2LINE3' by using a variable for the "2" digit in '2LINE3' instead of the "2" digit itself, and i don't even know if this kinda thing can be done.

this code syntax below does not work specifically in the WHERE segment where i try to mix the variable with the actual text in the column:


$sql = "UPDATE overall SET iltr='Y' WHERE refline='$slotLINE3'";

i hope you can forgive my inexperience. thanks again and have an awesome day!


Your code is trying to substitute a variable named $slotLINE3. You need to use a delimiter to end the variable name.

$sql = "UPDATE overall SET iltr='Y' WHERE refline='{$slot}LINE3'";