mysqli_query inputs via variable

后端 未结 3 1892
太阳男子
太阳男子 2021-01-28 06:00

I\'m trying to add information to a MySQL table using the following PHP code. (The input the name and text from an HTML5 basic web form.) Probably a syntax issue?



        
3条回答
  •  逝去的感伤
    2021-01-28 06:36

    This is how your code should look (with added SQL Injection protection):

    
    

    Take a look at what I've done. Firstly I've escaped the user input you're retrieving into the $name and $text variables (this is pretty much a must for security reasons) and as others have suggested you should preferably be using prepared statements.

    The problem is that you weren't surrounding string values with single quotes ('), which is a requirement of the SQL syntax.

    I hope this helps to answer your question.

提交回复
热议问题