0
情況: 我有changepass頁面來更改密碼。但頁面無法檢索並顯示數據庫中的值。我想顯示已存儲在數據庫中的ID,名稱和部門。該newpasswword也不能更新... plz..help我..無法檢索數據庫中的值並且無法更新表
下面的代碼:
<?php
session_start();
$username = $_SESSION["username"];
?>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("fyp", $con);
$username=$_SESSION["username"];
$query = "SELECT * from access WHERE username = '$username'";
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
$username = $row["username"];
$name = $row["name"];
$department = $row["department"];
mysql_query($query) or die ("Query Failed".mysql_error());
//mysql_close($link);
if(isset($_POST['submit']))
{
if (!$_POST['newpassword'])
{
echo "<script language='Javascript'>alert(' Please Enter The New Password');</script>";
}
else
{
$newpassword=$_POST['newpassword'];
if(!eregi("^[[:alnum:]]{6,12}$", $newpassword))
{
echo "<script language='Javascript'>alert(' New Password must be 6-12 element');</script>";
}
else {
$query1 = "UPDATE access SET password=$newpassword WHERE username = '$username'";
mysql_query($query1) or die ("Query Failed".mysql_error());
echo "<script> alert('Change Password Success. Please Login With The New Password.');
document.location.href='login.php?mosmsg=Please enter the value'</script>\n";
}
}
}
?>
<font face= "arial" size="2" font color="black">
<center>
<h3 align=center> Change Password </h3>
<table width="500" height="100" border="0" cellspacing="0" cellpadding="2">
<tr>
<tr>
<td align="left">User ID</td>
<td>: <? {echo "$username"; } ?></td>
</tr>
<tr>
<td align="left">Name </td>
<td>: <? {echo "$name"; } ?></td>
</tr>
<tr>
<td align="left">Department </td>
<td>: <?php echo $row['department']; ?> </td>
</tr>
<tr>
<td align="left">New Password </td>
<td>: <input name="newpassword" type="password" id="newpassword" size="20" ></td>
</tr>
我已經刪除了該聲明並用您的代碼替換..但它仍處於相同的情況。價值不顯示,當我點擊提交按鈕,它變成空白.. – user273551 2010-02-28 08:01:12
@ ejah85:我更新了我的答案,檢查編輯部分。謝謝 – Sarfraz 2010-02-28 08:06:02
我按照你的建議......但它似乎不工作......它仍然在相同的情況..我不知道代碼有什麼問題.. – user273551 2010-02-28 08:19:18