验证问题阻止使用 PHP 更新数据库

发布于 2024-10-05 16:17:24 字数 2045 浏览 5 评论 0原文

我正在使用以下 PHP 代码来更新数据库中的信息,但在更新发生之前,系统会提示我完成所有字段,即使所有字段都已完成

谁能明白为什么会发生这种情况吗?

这是我的代码

<?php

$update = strip_tags($_POST['update']); 

$username = strtolower(strip_tags($_POST['username']));

$olspassword = strip_tags($_POST['oldpassword']);

$newpassword = strip_tags($_POST['newpassword']);

$firstname = strip_tags($_POST['first']);

$lastname = strip_tags($_POST['last']);

$gender = strip_tags($_POST['gender']);

$address = strip_tags($_POST['address']);

$zipcode = strip_tags($_POST['zip']);

$contact = strip_tags($_POST['con']);

$email = strip_tags($_POST['mail']);

error_reporting(0);



if($update)
{




if($username&&$oldpassword&&$newpassword&&$firstname&&$lastname&&$address&&$zipcode&&$contact&&$email)
{

 $connect = mysql_connect("localhost","root","") or die(mysql_error());
 mysql_select_db(brightlights) or die(mysql_error());

 $updatecheck = mysql_query("SELECT username FROM tb_user WHERE username='$username'");
 $count = mysql_num_rows($updatecheck);
 if($count<=1)
 {

 if($_SESSION['password']==($oldpassword))
 {

 mysql_query("UPDATE tb_user SET
     username = '$username',
     password = '$newpassword',
     Firstname = '$firstname',
     Lastname = '$lastname',
     gender = '$gender',
     address = '$address',
     zipcode = '$zipcode',
     contact = '$contact',
     email = '$email'
     WHERE username='".$_SESSION['username']."'");
     $_SESSION['username'] = $username;
     $_SESSION['password'] = $newpassword;
     $_SESSION['Firstname'] = $firstname;
     $_SESSION['Lastname'] = $lastname;
     $_SESSION['gender'] = $gender;
     $_SESSION['address'] = $address;
     $_SESSION['zipcode'] = $zipcode;
     $_SESSION['contact'] = $contact;
     $_SESSION['email'] = $email;
     session_write_close();
     echo "Succesfully Updated!";

    }else
     echo "Password not match!";
   }else
    echo "Username already Taken!";
  }else
   echo "Please fill up all form!";
}
?>

I am using the following PHP code to update information in a database but before the update can occur, I am prompted to complete all fiels even though all of the fields hav already been completed

Can anyone see why this is happening?

Here's my code

<?php

$update = strip_tags($_POST['update']); 

$username = strtolower(strip_tags($_POST['username']));

$olspassword = strip_tags($_POST['oldpassword']);

$newpassword = strip_tags($_POST['newpassword']);

$firstname = strip_tags($_POST['first']);

$lastname = strip_tags($_POST['last']);

$gender = strip_tags($_POST['gender']);

$address = strip_tags($_POST['address']);

$zipcode = strip_tags($_POST['zip']);

$contact = strip_tags($_POST['con']);

$email = strip_tags($_POST['mail']);

error_reporting(0);



if($update)
{




if($username&&$oldpassword&&$newpassword&&$firstname&&$lastname&&$address&&$zipcode&&$contact&&$email)
{

 $connect = mysql_connect("localhost","root","") or die(mysql_error());
 mysql_select_db(brightlights) or die(mysql_error());

 $updatecheck = mysql_query("SELECT username FROM tb_user WHERE username='$username'");
 $count = mysql_num_rows($updatecheck);
 if($count<=1)
 {

 if($_SESSION['password']==($oldpassword))
 {

 mysql_query("UPDATE tb_user SET
     username = '$username',
     password = '$newpassword',
     Firstname = '$firstname',
     Lastname = '$lastname',
     gender = '$gender',
     address = '$address',
     zipcode = '$zipcode',
     contact = '$contact',
     email = '$email'
     WHERE username='".$_SESSION['username']."'");
     $_SESSION['username'] = $username;
     $_SESSION['password'] = $newpassword;
     $_SESSION['Firstname'] = $firstname;
     $_SESSION['Lastname'] = $lastname;
     $_SESSION['gender'] = $gender;
     $_SESSION['address'] = $address;
     $_SESSION['zipcode'] = $zipcode;
     $_SESSION['contact'] = $contact;
     $_SESSION['email'] = $email;
     session_write_close();
     echo "Succesfully Updated!";

    }else
     echo "Password not match!";
   }else
    echo "Username already Taken!";
  }else
   echo "Please fill up all form!";
}
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

扭转时空 2024-10-12 16:17:25

这就是原因:

$olspassword = strip_tags($_POST['oldpassword']);
/// code
if($_SESSION['password']==($oldpassword)) {

代码块

if($_SESSION['password']==($oldpassword))

将始终为 false,因为 $oldpassword 从未设置。您这里有一个拼写错误:

$olspassword = strip_tags($_POST['oldpassword']);

看到变量 $olspassword?

This is the reason:

$olspassword = strip_tags($_POST['oldpassword']);
/// code
if($_SESSION['password']==($oldpassword)) {

The codeblock

if($_SESSION['password']==($oldpassword))

will always be false because $oldpassword is never set. You have a typo here:

$olspassword = strip_tags($_POST['oldpassword']);

See the variable $olspassword?

稍尽春風 2024-10-12 16:17:25
if($username&&$oldpassword&&$newpassword&&$firstname&&$lastname&&$address&&$zipcode&&$contact&`&$email)

让它像

if(isset($username) && isset($oldpassword)  and so on 
if($username&&$oldpassword&&$newpassword&&$firstname&&$lastname&&$address&&$zipcode&&$contact&`&$email)

make it like

if(isset($username) && isset($oldpassword)  and so on 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文