繁体   English   中英

为什么我的PHP注册不起作用?

[英]Why isn't my PHP Sign-Up not working?

我对我的PHP登录脚本有疑问。 我对PHP和MySQL非常陌生,因此在查看我的代码时请记住这一点。

<?php

include('connectdb.php')

//define
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$passwordconfirm=$_POST['passwordconfirm'];
$email=$_POST['email'];
$firstname=$_POST['firstname'];

//prevents from MySQL Injection
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$passwordconfirm = stripslashes($passwordconfirm);
$email = stripslashes($email);
$firstname = stripslashes($firstname);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$passwordconfirm = mysql_real_escape_string($passwordconfirm);
$email = mysql_real_escape_string($email);
$firstname = mysql_real_escape_string($firstname);

//Inserting In to Table
$sql = "INSERT INTO login3 (username, password, confirmpass, email, firstname)
VALUES ($myusername, $mypassword, $passwordconfirm, $email, $firstname)";

?>

这不应该将所有值插入表login3中吗?

插入时尚未在字符串中使用引号。 另外,您应该使用反引号。 您也应该使用mysqli_ *而不是mysql_ *函数,因为它们已被弃用。 同样,也没有理由像@AndyIbanez所说的那样存储确认的密码,从而改变您的表结构。 您甚至都没有查询过sql语句。 尝试这个 :-

$sql = "INSERT INTO `login3` (`username`, `password`, `email`,    
`firstname`)
VALUES ('$myusername', '$mypassword', '$email', '$firstname')"; 

$conn = new mysqli($host, $user, $password, $database);
if(!$conn->query($sql)){
    echo "ERROR : " . mysqli_error($conn);//this will display error while insering into the table
}

使用此查询

$sql = "INSERT INTO login3 ('username', 'password', 'confirmpass', 'email', 'firstname')
VALUES ('".$myusername."', '".$mypassword."', '".$passwordconfirm."', '".$email."', '".$firstname."')";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM