LIKE operator with $variable

后端 未结 6 2002
有刺的猬
有刺的猬 2020-12-18 13:24

This is my first question here and I hope it is simple enough to get a quick answer!

Basically, I have the following code:

$variable = curPageURL();
         


        
6条回答
  •  庸人自扰
    2020-12-18 13:52

    Use double quotes if you need to substitute variable values:

    ## this code is open for SQL injection attacks
    $query = "SELECT * FROM `tablename` WHERE `columnname` LIKE '$variable'";
    

    Or concat string manually:

    ## this code is open for SQL injection attacks
    $query = 'SELECT * FROM `tablename` WHERE `columnname` LIKE "' . $variable . '"';
    

提交回复
热议问题