你如何修复不在mysql中显示的用户名?

时间:2011-02-07 23:11:21

标签: phpmyadmin mysqldump

即时为我的网站创建一个注册表,到目前为止一切都很好,但是当你注册时,它不会将用户名放入数据库,它会输入密码和电子邮件

<?php
@mysql_connect("localhost", "user", "pass") or die("Cannot connect to DB!");
@mysql_select_db("") or die("Cannot select DB!");
$sql= "INSERT INTO member (username, password, email) VALUES('$loginid','$password','$email')";
$r = mysql_query($sql);
if(!$r) {
    $err=mysql_error();
    print $err;
    exit();
}
$insert_query = 'insert into member (username,password,email) values("' . $_POST['username'] . '","' . $_POST['password'] . '","' . $_POST['email'] . '")';

mysql_query($insert_query);
?>

提前感谢您的帮助:D

1 个答案:

答案 0 :(得分:0)

您确定表单中的元素名称是否正确?你是在发布表格而不是使用GET吗?此外,您不应该以纯文本形式将密码插入数据库,而是使用MySQL的password函数,也不应该形成类似的mysql语句,因为它会使您的数据库对SQL注入开放。试试这个:

$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$email = mysql_real_escape_string($_POST['email']);
$insert_query = "insert into member (username,password,email) values('$username', PASSWORD('$password'), '$email')";