|
|
|
ช่วยดูโค้ดให้หน่อยครับ ผมอยากให้ผู้ใช้ login เข้ามาแล้ว edit profile ได้ ผมทำฟร้อมง่ายๆ แต่พอ save มันไม่เปลี่ยน |
|
|
|
|
|
|
|
Code manege_profile_edit (PHP)
<?php
session_start();
if($_SESSION['user_id'] == "")
{
echo "Please Login!";
exit();
}
mysql_connect("localhost","root","123456");
mysql_select_db("dbboard");
mysql_query("SET NAMES UTF8");
$strSQL = "SELECT * FROM member WHERE user_id = '".$_SESSION['user_id']."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
?>
<html>
<head>
<title>EDIT Profile!</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.auto-style1 {
text-align: right;
}
.auto-style2 {
text-align: center;
}
</style>
</head>
<body>
<form name="form1" method="post" action="manage_profile_edit2.php">
<div class="auto-style2">
Edit Profile!
<br><br><br>
<!---------------------------------------------------- Table ------------------------------------------------------------->
<table width="400" border="1" style="width: 400px" align="center">
<tbody>
<tr>
<td class="auto-style1">No :</td>
<td><?php echo $objResult["user_id"];?>
</td>
</tr>
<tr>
<td class="auto-style1">ID :</td>
<td><?php echo $objResult["username"];?>
</td>
</tr>
<tr>
<td class="auto-style1">ชื่อ :</td>
<td><input name="txtFname" type="text" id="txtFname" value="<?php echo $objResult["fname"];?>"></td>
</tr>
<tr>
<td class="auto-style1">นามสกุล :</td>
<td><input name="txtLname" type="text" id="txtLname" value="<?php echo $objResult["lname"];?>"></td>
</tr>
<tr>
<td class="auto-style1">ชื่อเล่น :</td>
<td><input name="txtNname" type="text" id="txtNname" value="<?php echo $objResult["nname"];?>"></td>
</tr>
<tr>
<td class="auto-style1">เพศ :</td>
<td><select name="Sex" style="width: 100%; height: 30px;" class="auto-style6">
<option value=""><?php echo $objResult["sex"];?></option>
<option>Female</option>
<option>Male</option>
</select></td>
</tr>
<tr>
<td class="auto-style1">อายุ :</td>
<td><input name="txtAge" type="text" id="txtAge" value="<?php echo $objResult["age"];?>"></td>
</tr>
<tr>
<td class="auto-style1">วัน เดือน ปีเกิด :</td>
<td><input name="txtBirthday" type="text" id="txtBirathday" value="<?php echo $objResult["birthday"];?>"></td>
</tr>
<tr>
<td class="auto-style1">ที่อยู่ :</td>
<td><textarea cols="20" name="txtAddress" rows="2"><?php echo $objResult["address"];?></textarea></td>
</tr>
<tr>
<td class="auto-style1">เบอร์โทรศัพท์ :</td>
<td><input name="txtTel" type="text" id="txtTel" value="<?php echo $objResult["tel"];?>"></td>
</tr>
<!------------------------------------------------------------------------------------------->
<tr>
<td class="auto-style1">แผนก :</td>
<?
mysql_connect("localhost","root","123456") or die(mysql_error());
mysql_select_db("dbboard");
mysql_query("SET NAMES UTF8");
?>
<td>
<select name="Dep" style="width: 100%; height: 30px;">
<option value=""><?php echo $objResult["dep"];?></option>
<?
$strSQL2 = "SELECT * FROM department ORDER BY dep_id ASC";
$objQuery2 = mysql_query($strSQL2);
while($objResuut2 = mysql_fetch_array($objQuery2))
{
if($strDefault2 == $objResuut2["department"])
{
$sel = "selected";
}
?>
<option><?php echo $objResuut2["dep_name"];?></option>
<?
}
?>
</select></td>
</tr>
<!-------------------------------------------------------------------------------------------->
<tr>
<td class="auto-style1">ตำแหน่งงาน :</td>
<?
mysql_connect("localhost","root","123456") or die(mysql_error());
mysql_select_db("dbboard");
mysql_query("SET NAMES UTF8");
?>
<td><select name="Pos" style="width: 100%; height: 30px;">
<option value=""><?php echo $objResult["pos"];?></option>
<?
$strSQL3 = "SELECT * FROM position ORDER BY pos_id ASC";
$objQuery3 = mysql_query($strSQL3);
while($objResuut3 = mysql_fetch_array($objQuery3))
{
if($strDefault3 == $objResuut3["position"])
{
$sel = "selected";
}
?>
<option><?php echo $objResuut3["pos_name"];?></option>
<?
}
?>
</select></td>
</tr>
<tr>
<td class="auto-style1">เบอร์โทรแผนก :</td>
<td><input name="txtTeldep" type="text" id="txtTeldep" value="<?php echo $objResult["tel.dep"];?>"></td>
</tr>
</tbody>
</table>
<!--------------------------------------------------------------------------------------------------------------------------->
<br><br><br>
<input type="submit" name="Submit" value="Save">
</div>
</form>
</body>
</html>
Code manage_profile_edit2 (PHP)
<?php
session_start();
if($_SESSION['user_id'] == "")
{
echo "Please Login!";
exit();
}
mysql_connect("localhost","root","123456");
mysql_select_db("dbboard");
mysql_query("SET NAMES UTF8");
$strSQL = "UPDATE member SET fname = '".trim($_POST['txtFname'])."' ,
lname = '".trim($_POST['txtLname'])."' ,
nname = '".trim($_POST['txtNname'])."' ,
sex = '".trim($_POST['Sex'])."' ,
age = '".trim($_POST['txtAge'])."' ,
birthday = '".trim($_POST['txtBirthday'])."' ,
address = '".trim($_POST['txtAddress'])."' ,
tel = '".trim($_POST['txtTel'])."' ,
dep = '".trim($_POST['Dep'])."' ,
pos = '".trim($_POST['Pos'])."' ,
tel.dep = '".trim($_POST['txtTeldep'])."'
WHERE user_id = '".$_SESSION["user_id"]."' ";
$objQuery = mysql_query($strSQL);
echo "Save Completed!<br>";
if($_SESSION["status"] == "Admin")
{
echo "<br> Go to <a href='page_admin.php'>Admin page</a>";
}
else
{
echo "<br> Go to <a href='page_user.php'>User page</a>";
}
mysql_close();
?>
<?
$host = "localhost";
$user = "root";
$pass = "123456";
$db = "dbboard";
$tbl = "member";
mysql_connect($host, $user, $pass) or die("Can not contact the database server.");
mysql_select_db($db) or die("cannot select the database.");
mysql_query("SET NAMES UTF8");
$strSQL1 = "SELECT * FROM department WHERE dep_id = '".$_POST["dep"]."' ";
$objQuery1 = mysql_query($strSQL1);
$objResult1 = mysql_fetch_array($objQuery1);
mysql_close();
?>
<?
$hostname = "localhost";
$username = "root";
$password = "123456";
$dbname = "dbboard";
$tblname = "member";
mysql_connect($hostname, $username, $password) or die("Can not contact the database server.");
mysql_select_db($dbname) or die("cannot select the database.");
mysql_query("SET NAMES UTF8");
$strSQL2 = "SELECT * FROM position WHERE pos_id = '".$_POST["pos"]."' ";
$objQuery2 = mysql_query($strSQL2);
$objResult2 = mysql_fetch_array($objQuery2);
mysql_close();
?>
ช่วยแนะนำทีครับ ขอบคุณครับผม
Tag : PHP, MySQL, HTML/CSS, JavaScript, jQuery, Windows
|
|
|
|
|
|
Date :
2015-08-31 00:00:20 |
By :
NuItMaster |
View :
714 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87-91, 114-118 เอาออกครับ ไม่จำป็นต้อง connect ใหม่ แค่ 013-015 อันเดียวพอครับ
ไฟล์ 2 ก็เหมือนกัน 41-49, 59-67 เอาออกครับ
ส่วนบันทัดที่ 25. เพิ่มสีแดงเข้าไปจะได้รู้ว่า error อะไร และสีนำเงิน กรณี ไม่เข้าเคส where
$objQuery = mysql_query($strSQL) or die(mysql_error() . "<br>$strSQL");
if( mysql_affected_rows()==0) echo 'There is not update anything';
|
|
|
|
|
Date :
2015-08-31 04:50:31 |
By :
NewbiePHP |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณครับ ได้แล้วครับ ^^
|
|
|
|
|
Date :
2015-08-31 10:35:58 |
By :
NuItMaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|