我正在创建一个网站,允许用户注册帐户并使用它登录。
现在,我希望他们能够更新他们的用户名和电子邮件等详细信息。我已经按照指南here进行了操作,因为我碰巧在register.php中使用了与他相同的代码,但它没有用。我是php的初学者,所以请耐心等待!感谢帮助。
register.php
<form method="post" action="">
<select name="find">
<option value = "a">I'm a regular customer</option>
<option value = "b">TV advertision</option>
<option value = "c">Phone directory</option>
<option value = "d">Word of mouth</option>
</select>
<input type="submit" name="submit" value="submit"/>
</form>
if(isset($_POST['submit']))
{
$find=$_POST['find'];
switch($find) {
case "a" :
echo "<p>Regular customer.</p>";
break;
case "b" :
echo "<p>TV advertision.</p>";
break;
case "c":
echo "<p>Phone directory.</p>";
break;
case "d":
echo "<p>Customer referred by word of mouth.</p>";
break;
default :
echo "<p>We don't know.</p>";
break;
}
}
当我输入editprofile.php时,页面为空白。这是我的 editprofile.php
<?php
if(!empty($_POST['username']) && !empty($_POST['password']))
{
$username = mysql_real_escape_string($_POST['username']);
$password = md5(mysql_real_escape_string($_POST['password']));
}
$email = mysql_real_escape_string($_POST['email']);
$checkusername = mysql_query("SELECT * FROM users WHERE username = '".$username."'");
if(mysql_num_rows($checkusername) == 1)
{
echo "<h1>Error</h1>";
echo "<p>Sorry, that username is taken. Please go back and try again.</p>";
}
else
{
$registerquery = mysql_query("INSERT INTO users (username, password, email) VALUES('".$username."', '".$password."', '".$email."')");
if($registerquery)
{
echo "<h1>Success</h1>";
echo "<p>Your account was successfully created. Please <a href=\"index.php\">click here to login</a>.</p>";
}
else
{
echo "<h1>Error</h1>";
echo "<p>Sorry, your registration failed. Please go back and try again.</p>";
}
}
?>
<h1>Register</h1>
<p>Please enter your details below to register.</p>
<form method="post" action="register.php" name="registerform" id="registerform">
<fieldset>
<label for="username">Username:</label><input type="text" name="username" id="username" /><br />
<label for="password">Password:</label><input type="password" name="password" id="password" /><br />
<label for="email">Email Address:</label><input type="text" name="email" id="email" /><br />
<input type="submit" name="register" id="register" value="Register" />
</fieldset>
</form>
</div>
</body>
</html>
答案 0 :(得分:1)
<?php
include "base.php";
session_start();
?>
<?php
if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['username']))
{
$nameuser = $_SESSION['username'];
$checkinfo = mysql_query("SELECT * FROM users WHERE username = '$nameuser'");
while($results = mysql_fetch_array($checkinfo,MYSQL_ASSOC)){
$id = $row['id'];
$username = $row['username'];
$email = $row['email'];
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$editNAME=$_POST['username'];
$editEMAIL=$_POST['email'];
$editID=$_POST['id'];
$editquery = mysql_query("UPDATE users SET username='$editNAME' , email='$editEMAIL' WHERE id='$editID'");
if($editquery)
{
echo "<b>Success!</b>";
echo "Your profile was successfully updated. Please click<a href=\"profile.php\"> here </a>to view.";
}
else
{
echo "<b>Error</b>";
echo "<p>Sorry, your profile update failed. Please go back and try again.</p>";
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Edit Profile</title>
<link rel="stylesheet" href="styles.css" type="text/css" />
</head>
<body>
<form method="post" action="editprofile.php" name="editform" id="editform">
<p>Username: <input type="text" name="username" id="username" value="<?php echo $username; ?>" /></p>
<p>Email Address : <input type="email" name="email" id="email" value="<?php echo $email; ?>"></p>
<input type="submit" name="save" value="Save"/>
<input type="hidden" name="id" value="<?php echo $id; ?>" />
</form>
</body>
你试试这个...... 不是100%肯定,但你试试..