gpt4 book ai didi

php - 不使用$ _GET 'Undefined Index']格式时如何解决[''错误?

转载 作者:行者123 更新时间:2023-12-03 07:58:31 24 4
gpt4 key购买 nike

我正在编写用于登录密码恢复的代码,因此,我需要一个名为“recoverykey”的$ _GET值。每当我访问网页时未定义 recoverykey 时,它就会告诉我未定义索引错误。当然,会发生错误,但是我不需要表达 recoverykey 的值,那么如何删除该错误?

当我使用url时,错误看起来像这样: localhost/websites/index.php

Error looks like this

当我在url上时,该错误消失: localhost/websites/index.php?recoverykey = 39238579857

代码如下:

<?php

$change_code = $_GET['recoverykey'];

$sqlQuery = "SELECT * FROM RegisteredMembers WHERE RecoveryCode='$change_code'";
$result = mysqli_query($conn,$sqlQuery);
$fetch_result = mysqli_fetch_array($result);
$row_count = mysqli_num_rows($result);
if($row_count==1 && !$change_code==0){

$error = false;

$passError = null;
$output = null;
$errorMsg = null;

if(isset($_POST['btn-changepass-submit'])){

$password = $_POST['change-pass'];

// Password Validation
if(empty($password)){
$error = true;
$passError = "Please write your new password.";
} else if(strlen($password)<8){
$error = true;
$passError = "Passwords should atleast be 8 chars long.";
}

// If no error, continue
if(!$error){
/*$fetch_result['userEmail'] = $email;*/
$dtbQuery = "UPDATE RegisteredMembers SET password='$password' WHERE RecoveryCode='$change_code'";
$new_result = mysqli_query($conn,$dtbQuery);
if($new_result){
$errorType = "success";
$errorMsg = "Successfully changed password. <a href=#login-login>Login here</a>.";

$dbQuery = "UPDATE RegisteredMembers SET RecoveryCode='0' WHERE RecoveryCode='$change_code'";
$new_output = mysqli_query($conn,$dbQuery);

} else{
$errorType = "danger";
$errorMsg = "There seems to be an error. Please try again!";
}
}

}

?>
<div id="login-passchange">
<h2>Change your Password</h2>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?recoverykey=<?php echo $change_code ?>#login-passchange">
<span class="<?php echo $errorType; ?>-msg">
<?php
if($output){
echo $errorMsg;
} else{
echo $errorMsg;
}
?>
</span>
<label><span class="danger-msg"><?php echo $passError; ?></span><input type="password" placeholder="Write your New Password" maxlength="255" name="change-pass" required /></label>
<input type="submit" value="Set new Password" name="btn-changepass-submit" />
</form>
<div class="lower-part">
<a class="login-link" href="#login-login">Password Found? Login</a>
<br />
<a class="home-link" href="#home">Go back</a>
</div>
</div>
<?php
} else{
?>
<div id="login-passchange">
<h2>Error 404!</h2>
</div>
<?php
}

?>


该代码在更改密码方面取得了成功,但是我不希望出现该错误消息。此外,我尝试在StackOverflow上找到此问题,但该问题没有具体答案。因此,它永远不会重复。

在此先感谢您的帮助!

最佳答案

用这个

$change_code = isset($_GET['recoverykey']) ? $_GET['recoverykey'] : '';

关于php - 不使用$ _GET 'Undefined Index']格式时如何解决[''错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44082886/

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