douyi5157 2014-07-03 12:45
浏览 27
已采纳

PHP中的SQL查询语法错误

I am trying to do a simple query on my MySQL db and echo back the result. I am getting the following error:

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)

This is the code for my query:

$result = mysqli_query($connection, "SELECT FROM table_name WHERE value='$_POST["searchname"]'";
echo $result;

I'm assuming it is a simple syntax error in the SQL statement, but I just am not seeing it. Thanks for the help!

  • 写回答

3条回答 默认 最新

  • dongxie7683 2014-07-03 12:47
    关注

    You need to ensure you are using quotes appropriately when building a string:

    $result = mysqli_query($connection, "SELECT * FROM table_name WHERE value='".$_POST["searchname"]."'";
    

    Also I hope you are aware that either way this type of statement is vulnerable to sql injections. You should ideally use prepared statements or some sort of validation or escape to the input.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部