gpt4 book ai didi

php - 如何为mysql数据库创建用户?

转载 作者:行者123 更新时间:2023-11-30 00:05:42 24 4
gpt4 key购买 nike

我正在尝试创建用户并将其保存到我的数据库中。我有这个带有 css 和 html 的登录公式以及将其放入我的数据库的代码:

function registerUser()
{

echo "
<form method='get' action=''>
<div style=\"text-align: center;\"><input class=\"button\" style=\"z-index:1;\" type=\"submit\" name=\"reset\" value=\"Neues Spiel\">
<a href=\"?site=highscore\" class=\"button\" style=\"z-index:1;\">Zur Highscore</a>
</form>


<form style=\"border:5; border-color:blue; \" align=\"center\" action=\"\" method=\"post\">
<table style='background-color:#696969' border='5' align='center'>

<tr>
<th>Dein Username:</th>
</tr>
<tr>
<td><input type=\"text\" size=\"24\" maxlength=\"50\"
name=\"username\"></td>
</tr>
<tr>
<th>Dein Passwort:</th>
</tr>
<tr>
<td><input type=\"password\" size=\"24\" maxlength=\"50\"
name=\"password\"></td>
</tr>
<tr>
<th>Passwort Wiederholen:</th>
</tr>
<tr>
<td><input type=\"password\" size=\"24\" maxlength=\"50\"
name=\"password2\"></td>
</tr>

<tr><td><input style=\"margin-left:49;\" align=\"center\" type=\"submit\" value=\"Abschicken\" name=\"saveUser\"></tr></td>
</table>
</form>
";

}

和我的saveUser()函数:

function saveUser($username, $password, $passwordCheck)
{
$this->db->exec("INSERT INTO users (username, password) VALUES ({$username}, {$password})");
}

我在其他文档中得到了这个以获得访问权限:

if(isset($_GET['saveUser'])){
$user->saveUser($_GET['username'],$_GET['password'],$_GET['password2']);
}

它不起作用。

最佳答案

修改您的代码并使用它:

$this->db->exec("INSERT INTO users (username, password) VALUES ('{$username}', '{$password}')");

还有一件事您忘记了,您需要验证数据以避免 SQL 注入(inject),永远不要相信来自任何类型的用户的输入。

关于php - 如何为mysql数据库创建用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24575140/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com