嗨,我想讓用戶更新自己的詳細信息(個人資料頁面) 我的頁面正常工作,但是當我點擊更新按鈕時,頁面只是刷新,細節保持不變這是我的代碼。php-編輯用戶的個人資料頁面
<?php
session_start();
include_once 'dbconfig.php';
if(!isset($_SESSION['user']))
{
header("Location: index.php");
}
$res=mysql_query("SELECT * FROM users WHERE user_id=".$_SESSION['user']);
$userRow=mysql_fetch_array($res);
if(isset($_POST['username']))
{
$username= $_POST['username'];
$id = $_POST['user_id'];
$sql = "UPDATE users SET user_name='$username' user_id=".$_SESSION['user'];
$res = mysql_query($sql)
or die("Could not update".mysql_error());
echo "<meta http-equiv='refresh' content='0;url=profile.php'>";
}
if(isset($_POST['useremail']))
{
$useremail= $_POST['useremail'];
$id = $_POST['user_id'];
$sql = "UPDATE users SET user_email='$useremail' WHEREuser_id=".$_SESSION['user'];
$res = mysql_query($sql)
or die("Could not update".mysql_error());
echo "<meta http-equiv='refresh' content='0;url=profile.php'>";
}
if(isset($_POST['userabout']))
{
$userabout= $_POST['userabout'];
$id = $_POST['user_id'];
$sql = "UPDATE users SET user_about='$userabout' WHERE user_id=".$_SESSION['user'];
$res = mysql_query($sql)
or die("Could not update".mysql_affected_rows());
echo "<meta http-equiv='refresh' content='0;url=profile.php'>";
}
error_reporting(-1);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><?php echo $userRow['user_email']; ?>s Profile</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div class="box">
<input type="button"/>
<div class="menubar">
<div class="menu">
<ul id="menubar">
<li><?php echo $userRow['user_email']; ?><a href="logout.php?logout">Sign Out</a></li>
</ul>
</div>
<div class="menu1">
<ul id="menubar">
<li><a class="upload" href="index1.php">Upload</a></li>
</ul>
</div>
</div>
<div class="main">
<form action="profile.php" method="POST">
<div>
<label for="uname"><a>User Name:</a></label>
<input type="text" name="username" value="<?php echo $userRow['user_name'];?>"/>
</div>
<div>
<label for="email"><a>Email:</a></label>
<input type="text" name="useremail" value="<?php echo $userRow['user_email'];?>"/>
</div>
<div>
<label for="about"><a>About me:</a></label>
<textarea name="userabout" rows="10" cols="30"><?php echo $userRow['user_about'];?></textarea>
</div>
<input type="submit" value="Update">
<div>
</div>
</form>
</div>
<div id="mainv">
<table width="80%" border="1">
<tr>
<th colspan="4">your uploads...<label><a href="index.php">upload new files...</a></label></th>
</tr>
<tr>
<td>File Name</td>
<td>File Type</td>
<td>File Size(KB)</td>
<td>View</td>
</tr>
<video width="700" height="500" controls="autoplay">
<source src="mmm.mp4" type="video/mp4">
</video>
<?php
$sql="SELECT * FROM tbl_uploads";
$result_set=mysql_query($sql);
while($row=mysql_fetch_array($result_set))
{
?>
</source>
<tr>
<td><?php echo $row['file'] ?></td>
<td><?php echo $row['type'] ?></td>
<td><?php echo $row['size'] ?></td>
<td><a href="uploads/<?php echo $row['file'] ?>"target="frame_a">view file</a></td>
</a>
</tr>
<?php
}
?>
</table>
</div>
<div class="mid">
<div class="main2"><div class="pop"><div class="pop1"><h2>More Popular videos<h2></div><div class="pop2"></div></div></div>
<div class="com"><div class="comm"><div class="comm1"><h2>Best comments of the week<h2></div><div class="comm2"></div></div></div>
</div>
</body>
</html>
我知道這是老的PHP,但我通過我意識到有更新版本的項目開始了我的項目,它的一半。
你能幫我在這裏謝謝。
****我編輯了代碼,我收到了關鍵錯誤**** 無法更新您的SQL語法中有錯誤;請檢查與您的MySQL服務器版本對應的手冊,以便在第1行的'user_id = 36'附近使用正確的語法。
什麼錯誤? –
如果你想真正想知道你的更新是否工作,使用'mysql_affected_rows()'http://php.net/manual/en/function.mysql-affected-rows.php,因爲你可能會在這裏得到誤報。然而,爲什麼'include_once'dbconfig.php';'的倍數? –
當你刷新頁面(使用瀏覽器刷新按鈕)時,你看到你的更新?如果是,那麼在「更新」記錄 – codisfy