|
|
|
MySQL UPDATE record ไม่ได้ ไม่ทราบว่าโค้ดผิดยังไงครับ |
|
|
|
|
|
|
|
โค้ดแบบเต็มครับ
Code (PHP)
<?php
session_start();
////////////////////////////////////
/////////*Page Config Zone*/////////
////////////////////////////////////
$pagename = "EditUser";
$pageperm = "admin";
?>
<?php require("../../header.php"); ?>
<?php
switch ($_POST["submit"])
{
case "edit":
?>
<?php
$sql="SELECT * FROM $tb_member WHERE username='".$_POST["user"]."'";
$sql=mysqli_query($sqlcon,$sql);
$numsql=mysqli_num_rows($sql);
if ($numsql=="1")
{
$sql=mysqli_fetch_array($sql);
}
else
{
$sql="error";
}
if ($sql=="error")
{
echo'<div class="text-center">';
echo'<div class="alert alert-error">ไม่มีชื่อผู้ใช้นี้ในระบบ</div></div>';
}
else
{
?>
<h2 align="center">แก้ไขข้อมูลสมาชิก</h2>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="memberedit">
<table width="90%" border="1" align="center" cellpadding="5" cellspacing="0" id="registermember">
<tr>
<td>User ID</td>
<td><input name="id" type="text" maxlength="20" placeholder="uid" value="<?=stripslashes($sql["id"])?>" disabled></td>
</tr>
<tr>
<td>Username [A-Z,a-z,0-9,_เท่านั้น]</td>
<td><input name="username" type="text" maxlength="20" placeholder="Username" required value="<?=stripslashes($sql["username"])?>"></td>
</tr>
<tr>
<td>Password [A-Z,a-z,0-9,_เท่านั้น]</td>
<td><input name="password" type="password" maxlength="64" placeholder="Password ถูกเข้ารหัสไว้ไม่สามารถเรียกดูได้"></td>
</tr>
<tr>
<td>ชื่อเล่น</td>
<td><input name="nickname" type="text" maxlength="20" placeholder="Nickname" required value="<?=stripslashes($sql["nickname"])?>"></td>
</tr>
<tr>
<td>Email [ใช้ในการยืนยันการสมัคร]</td>
<td><input name="email" type="text" maxlength="64" placeholder="Email" required value="<?=stripslashes($sql["email"])?>"></td>
</tr>
<tr>
<td>เพศ [Sex]</td>
<td>
<select name="sex">
<option value="1" <?php if($sql["sex"]=="1"){echo'selected="selected"';} ?>>ชาย</option>
<option value="2" <?php if($sql["sex"]=="2"){echo'selected="selected"';} ?>>หญิง</option>
<option value="3" <?php if($sql["sex"]=="3"){echo'selected="selected"';} ?>>ชายชอบชาย</option>
<option value="4" <?php if($sql["sex"]=="4"){echo'selected="selected"';} ?>>หญิงชอบหญิง</option>
</select></td>
</tr>
<tr>
<td>Facebook</td>
<td><input name="facebook" type="text" maxlength="64" placeholder="facebook" value="<?=stripslashes($sql["facebook"])?>"></td>
</tr>
<tr>
<td>เกี่ยวกับฉัน</td>
<td><textarea name="aboutme" cols="45" rows="5" placeholder="เขียนเกี่ยวกับตัวเรา"><?=stripslashes($sql["aboutme"])?></textarea></td>
</tr>
<tr>
<td>Status [ชนชั้น]</td>
<td>
<select name="status">
<option value="1" <?php if($sql["status"]=="1"){echo'selected="selected"';} ?>>Member</option>
<option value="2" <?php if($sql["status"]=="2"){echo'selected="selected"';} ?>>Server Member</option>
<option value="3" <?php if($sql["status"]=="3"){echo'selected="selected"';} ?>>Staff</option>
<option value="4" <?php if($sql["status"]=="4"){echo'selected="selected"';} ?>>Police</option>
<option value="5" <?php if($sql["status"]=="5"){echo'selected="selected"';} ?>>Admin</option>
</select></td>
</tr>
<tr>
<td colspan="2" style="text-align:center; vertical-align:central">
<input name="submit" type="submit" class="btn btn-primary btn-large" value="edituser">
</td>
</tr>
</table>
</form>
<?php
}
break;
case "edituser":
$edit["id"]=$_POST["id"];
$edit["username"]=$_POST["username"];
$edit["email"]=$_POST["email"];
$edit["nick"]=$_POST["nickname"];
$edit["password"]=$_POST["password"];
$edit["sex"]=$_POST["sex"];
$edit["facebook"]=$_POST["facebook"];
$edit["aboutme"]=$_POST["aboutme"];
$edit["status"]=$_POST["status"];
$sql = "UPDATE $tb_member SET ";
$sql .="nickname = '".$edit["nick"]."' ";
$sql .=", email = '".$edit["email"]."' ";
$sql .=", username = '".$edit["username"]."' ";
$sql .=", sex = '".$edit["sex"]."' ";
if ($_POST["facebook"]!="")
{
$sql .=", facebook = '".$edit["facebook"]."' ";
}
$sql .=", status = '".$edit["status"]."' ";
if ($_POST["password"]!="")
{
$sql .=", password = '".$edit["password"]."' ";
}
if ($_POST["aboutme"]!="")
{
$sql .=", aboutme = '".$edit["aboutme"]."' ";
}
$sql .="WHERE id ='".$edit["id"]."'";
$sql=mysqli_query($sqlcon,$sql);
if($sql)
{
echo'<div class="text-center">';
echo'<div class="alert alert-success">แก้ไขข้อมูลเรียบร้อยแล้ว</div></div>';
}
else
{
echo'<div class="text-center">';
echo'<div class="alert alert-error">เกิดข้อผิดพลาดขึ้นในระบบไม่สามารถบันทึกได้</div></div>';
}
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="memberedit">
</form>
<?php
break;
default:
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="memberedit">
<p align="center"><label>กรุณากรอกUsernameที่ต้องการแก้ไข : <input name="user" type="text" id="user" class="input-large" placeholder="Username"></label></p>
<p align="center"><input name="submit" type="submit" value="edit" class="btn btn-primary"></p>
</form>
<?php
}
?>
<?php require("../../footer.php"); ?>
|
|
|
|
|
Date :
2014-01-14 20:19:37 |
By :
KingdomOfGolf |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
$id=$_POST["id"];
$username=$_POST["username"];
$email=$_POST["email"];
$nick=$_POST["nickname"];
$password=$_POST["password"];
$sex=$_POST["sex"];
$facebook=$_POST["facebook"];
$aboutme=$_POST["aboutme"];
$status=$_POST["status"];
$sql = "UPDATE $tb_member SET
nickname = '$nick',
username = '$username ',
sex= '$sex' ,
facebook= '$facebook' ,
password= '$password' ,
aboutme= '$aboutme'
WHERE id = '$id' ";
$res=mysqli_query($sqlcon,$sql);
if($res)
{
echo'<div class="text-center">';
echo'<div class="alert alert-success">แก้ไขข้อมูลเรียบร้อยแล้ว</div></div>';
}
else
{
echo'<div class="text-center">';
echo'<div class="alert alert-error">เกิดข้อผิดพลาดขึ้นในระบบไม่สามารถบันทึกได้</div></div>';
|
|
|
|
|
Date :
2014-01-14 21:36:32 |
By :
champkung226 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|