2013-03-12 149 views
0

由於某些原因,這不會更新數據庫,數據庫登錄的值是正確的使用相同的INC文件的所有頁面。沒有錯誤,只是在數據庫沒有更新。似乎無法弄清楚我的生活。PHP到MySQL更新帖子不工作

<? 
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

等於密碼,你如何試圖弄明白? – Madbreaks 2013-03-12 22:04:41

+0

通過使用'var_dump()'來檢查你的UPDATE sql語句開始調試 – michi 2013-03-12 22:04:53

+0

你沒有檢查錯誤,所以難怪你沒有看到任何錯誤。請參閱http://php.net/mysql_error – 2013-03-12 22:05:03

回答

1

,而不是這個

if ($encrypted_password = $adminpass){ 

使用

if ($encrypted_password == $adminpass){ 

就可以解決這個問題,看看他們是否真的使用

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

似乎沒有做到這一點。 – ajankuv 2013-03-12 22:12:26

+0

沒有更新?與此修復 – 2013-03-12 22:14:49

+0

沒有'$ adminpass'加密也從數據庫?由md5 – 2013-03-12 22:17:00

1

我看到的第一個問題是$encrypted_password = $adminpass。使用==進行比較。

+0

$ userpost = $ _POST [「username」]; – ajankuv 2013-03-12 22:49:37