我正在尝试创建用户并将它们保存到我的数据库中。我有这个带有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']);
}它不起作用。
发布于 2014-07-04 21:15:22
修改您的代码并使用以下代码:
$this->db->exec("INSERT INTO users (username, password) VALUES ('{$username}', '{$password}')");还有一件事你忘记了,你需要验证你的数据以避免sql注入,永远不要相信来自任何类型用户的输入。
https://stackoverflow.com/questions/24575140
复制相似问题