简体   繁体   中英

php to mysql update post not working

For some reason this will not update the db, the values for the db login are correct use the same inc file for all the pages. No errors, just no updates in the db. Can't seem to figure it out for the life of me.

<?
include("../../inc/config.inc.php");
session_start();
$loggeduser = $_SESSION['myusername'];
if(!session_is_registered(myusername)){
header("location:login/login.php");
}
?>
<?
$userpost = $_POST["username"];
if(is_null($userpost)) {
mysql_connect("$host", "$user", "$pwd") or die(mysql_error());
mysql_select_db("$database") or die(mysql_error());
$server_query_sql = ("SELECT * FROM $admin_tbl WHERE username = '$loggeduser'");
$getdata = mysql_query($server_query_sql) or die("Couldn't execute the query");
$row = mysql_fetch_array( $getdata );
$adminuser = $row['username'];
$adminpass = $row['password'];
$adminemail = $row['email'];
mysql_close();
}
else {
$postemail = $_POST["email"];
$postpass = $_POST["password"];
$encrypted_password = md5($postpass);
mysql_connect("$host", "$user", "$pwd") or die(mysql_error());
mysql_select_db("$database") or die(mysql_error());
$server_query_sql = ("SELECT * FROM $admin_tbl WHERE username = '$loggeduser'");
$getdata = mysql_query($server_query_sql) or die("Couldn't execute the query");
$row = mysql_fetch_array( $getdata );
$adminuser = $row['username'];
$adminpass = $row['password'];
$adminemail = $row['email'];

if ($encrypted_password = $adminpass){
$query = "UPDATE $admin_tbl SET email='$postemail' WHERE username='$loggeduser'";
mysql_query($query);
}
else {
$query = "UPDATE $admin_tbl SET email='$postemail', password='$encrypted_password'     WHERE username='$loggeduser'";
    mysql_query($query);
mysql_close(); 
}
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="../../inc/login.css" />
    <style>
        @import url(http://fonts.googleapis.com/css?family=Ubuntu:400,700);
        body {

            -webkit-background-size: cover;
            -moz-background-size: cover;
            background-size: cover;
        }
        .container > header h1,
        .container > header h2 {
            color: #fff;
            text-shadow: 0 1px 1px rgba(0,0,0,0.7);
        }
    </style>
</head>
<body><br><br>
  <div align="center">Hi <strong><? echo $loggeduser; ?></strong>!</div>
   <div class="container">
        <section class="main">
            <form class="form-3" method="post" action='<? $_SERVER['PHP_SELF']; ?>'>
                <p class="clearfix">
                    <label for="login">Email</label>
                    <input type="text" name="email" id="email" placeholder="Username" value='<? echo $adminemail; ?>'>
                </p>
                <p class="clearfix">
                    <label for="password">Password</label>
                    <input type="password" name="password" id="password" placeholder="Password" value='<? echo $adminpass; ?>'> 
                </p>
                <p class="clearfix">
                    <input type="submit" name="submit" value="Edit">
                </p>       
            </form>​
        </section>
    </div>
</body>
</html>

First problem I see is $encrypted_password = $adminpass . Use == for comparison.

instead of this

    if ($encrypted_password = $adminpass){

use

   if ($encrypted_password == $adminpass){

you can fix this to see if they really equal the passwords by using

   echo $encrypted_password . ' ----- ' .$adminpass ;  // and see if they are same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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