Use a $variable inside a SQL string?

前端 未结 3 1381
傲寒
傲寒 2020-12-22 15:02

I would like to be able to select a category from a dropdown and depending on the category it will add it to whatever SQL table is it equal with.



        
3条回答
  •  离开以前
    2020-12-22 15:37

    I know this answer won't be too helpful for you right now, but sice there is just too much wrong with that code and that approach, here are a few tips:

    • Use PDO instead of PHP's MySQL functions. It'll seem daunting at first, especially if you haven't got any experience with object-oriented programming, but it's definately worth the effort.
    • Sanitize that $article value! if($article == 'foo' || $article == 'bar') {...}
    • The best ways to use variables in strings are: "This is a ".$adjective." string" and "This is a {$adjective} string"

提交回复
热议问题