doufu7835 2013-03-12 22:02
浏览 33
已采纳

php到mysql更新帖子无法正常工作

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>
  • 写回答

2条回答 默认 最新

  • doufuhao0566 2013-03-12 22:06
    关注

    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.
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向