且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP从表单输入数据到SQL数据库

更新时间:2023-10-08 10:48:52

你可以很容易地调用 addNewUser() 函数传递所需的参数:

You could easily just call the addNewUser() function passing the required parameters as:

addNewUser($connect,$username,$password,$dbtable);

一个更好的用法示例是首先检查表单是否已经提交,以通过检查表单字段是否已提交来防止任何直接访问或空记录和 PHP 警告,即.

A better usage example would be to first check that the form has been already submitted to prevent any direct access or empty records and PHP warnings by checking that form fields have been submitted, ie.

if(isset($_POST["username"]) && isset($_POST["password"]))
{
    $username=$_POST['username'];
    $password=$_POST["password"];

    addNewUser($connect,$username,$password,$dbtable);
 }

除此之外,这似乎是一个非常基本的示例,也是如何在数据库中实现新插入的不良做法,因此请确保不要在生产环境中使用任何这些.IE:

Other than that this seems to be a very basic example and also a bad practise on how to implement a new insert in the database so be sure not to use any of this in a production environment. IE:

  • 无输入过滤.
  • 试图模仿"用户的自动增量字段
  • 容易受到 SQL 注入的影响,如果用户尝试使用包含引号的用户名或密码进行注册,甚至可能会意外失败