gpt4 book ai didi

php - 我的代码不会写入 mysql 数据库

转载 作者:太空宇宙 更新时间:2023-11-03 12:29:36 26 4
gpt4 key购买 nike

我已经创建了一个登录系统,现在我正在尝试向其中添加重置密码代码。除了没有写入 Mysql 数据库外,一切似乎都运行良好。任何帮助将不胜感激。

    <?php
if(isset($_POST['submit'])){
$mycode = ($_POST['code']);
$mynewpass = ($_POST['password']);
$myconfpass = ($_POST['password1']);

//checks if all fields are filled
if( (empty($mynewpass)) || (empty($myconfpass)) || (empty($mycode)) ){
$errors[] = '<center>All fields must be filled in.<center>';
}
//check if passwords match
if ($mynewpass != $myconfpass){
$errors[] = '<center>Your passwords do not match</center>';
}
if (!empty($errors)){
foreach($errors as $error){
echo '<strong>',$error ,'</strong><br />';
}
}else{

include 'Grubconfig.php';

mysql_connect($host, $user, $password) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());

// change password
$mychk = mysql_query(" SELECT * FROM customer WHERE passreset = '$mycode' ");

if(mysql_num_rows($mychk) == 1)

mysql_query("UPADTE customer SET Password='$mynewpass' WHERE passreset='$mycode'");
mysql_query("UPADTE customer SET passreset='0' WHERE passreset='$mycode'");

echo '<center>Your password has been reset Please click <a href="Grublogin.php">here !</a><center>';
}

}?>

最佳答案

错别字:

 mysql_query("UPADTE customer SET Password='$mynewpass' WHERE passreset='$mycode'");
^^^^^^--- UPDATE (swap D and A)

永远不要假设您的查询是成功的。始终检查错误:

$result = mysql_query($sql) or die(mysql_error());
^^^^^^^^^^^^^^^^^^^^^^-- bare minimum error handling

您也对 SQL injection attacks 敞开心扉.因此,您最好在部署此代码之前阅读有关它们的信息并修复漏洞。

关于php - 我的代码不会写入 mysql 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16091293/

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