无法更新用户的个人资料

时间:2012-12-15 23:11:49

标签: php mysql

我做了一个程序。在此程序中,用户可以登录并更改用户配置文件中的详细信息。详细信息如下:用户名,密码,电子邮件。我的代码是:

Profile.php

<?php
include_once "db_connection.php";
if (isset($_GET['user_name']))
{
$user_name = $_GET['user_name'];
$result = mysql_query("SELECT * FROM users WHERE user_name LIKE '$user_name' ")
or die(mysql_error());
$row = mysql_fetch_assoc($result);
if($row)
{
$user_email = $row['user_email'];
}
else
{
echo "error";
}
}
?>

profile.php中的表单是:

<form id="form1" action="updateprofile.php" method="post" class="form">
<fieldset class="form-inline">
<div class="form-col-3-8" style="padding-top:10px;padding-bottom:20px;"align="center">
<label>UserName<span class="required">*</span></label>
<input type="text" name="user_name" value="<?php echo $user_name; ?>" />
</div>
<div class="form-col-2-8" style="padding-top:10px;padding-bottom:20px;"align="center">
<label>Password<span class="required">*</span></label>
<input type="password" name="password"/>
</div>
<div class="form-col-3-8" style="padding-top:10px;padding-bottom:20px;"align="center">
<label>E-mail<span class="required">*</span></label>
<input type="text" name="user_email" value="<?php echo $user_email; ?>" />
</div>
</fieldset>
<div class="da-button-row">
<input type="reset" value="Reset" />
<input type="submit" value="Submit" name="submit"/>
</div>
</form>

最后,updateprofile.php是:

<?php
include_once "db_connection.php";
if (isset($_POST['submit'])) 
{
$user_name = $_POST['user_name'];
$user_name2 = mysql_real_escape_string(htmlspecialchars($_POST['user_name']));
$password =  mysql_real_escape_string(htmlspecialchars($_POST['password']));
$passwordmd = md5($password);
$user_email = mysql_real_escape_string(htmlspecialchars($_POST['user_email']));
mysql_query("UPDATE users SET user_name='$user_name2', user_email='$user_email' ,user_password_hash='$passwordmd' WHERE user_name LIKE '$user_name'")
or die(mysql_error());
header("Location: index.php");
}
?>

一切正常,但是当我推送提交时,数据库中的细节不会改变。我做错了什么?

0 个答案:

没有答案