===สอบถามการอัพเดท แก้ไขข้อมูลจากฐานข้อมูลครับ===
เราสามารถระบุไอดี เพื่อทำหน้าแก้ไข หรืออัพเดทฐานข้อมูลได้เลยหรือไม่ครับ
ในที่นี้ผมต้องการใช้แก้ไขที่่ id=1 เท่านั้นครับ
หน้า manage_chat.php สามารถเรียกข้อมูลจากฐานข้อมูลได้ แต่ไม่สามารถแก้ไขได้
ส่วนหน้า Edit ครับ manage_chat.php
Code
ด้านบน
<?
include('../config/config.php');
include('../config/class_requestsong.php');
include('../config/check_db.php');
?>
ส่วนฟอร์ม
<?
$id = ""; // clear ค่ารหัส key ก่อนเพื่อความปลอดภัย
$sql = "select * from test_chat WHERE id =1";
$exec = $x->_query($sql);
while($db = mysql_fetch_array($exec))
{
$id = $db[id];
$usr = $db[usr];
$pwd = $db[pwd];
$bg = $db[bg];
$banner = $db[banner];
$color_t = $db[color_t];
$t_menu = $db[t_menu];
$color_t_menu = $db[color_t_menu];
$t_body = $db[t_body];
$color_t_body = $db[color_t_body];
}
?>
<body leftmargin=0 topmargin=0>
<form action="editdata.php" method="post">
<input type="hidden" name="id" value="<?=$id?>">
Password : <input name="pwd" type="text" value ="<?=$pwd?>" size="15" style="width: 700px" maxlength="15">
และ ที่เหลือไล่ลงมาทั้งหมด
หน้า editdata.php รับค่าแก้ไข
Code
ด้านบน
<?
include('../config/config.php');
include('../config/class_requestsong.php');
include('../config/check_db.php');
?>
ส่วนบอดี้
<?
$id = $_GET['id'];
$sql = "select * from test_chat WHERE id = 1";
$exec = $x->_query($sql);
while($db = mysql_fetch_array($exec))
{
$id = $db[id];
$user = $db[user];
$pass = $db[pass];
$bg = $db[bg];
$banner = $db[banner];
$color_t = $db[color_t];
$t_menu = $db[t_menu];
$color_t_menu = $db[color_t_menu];
$t_body = $db[t_body];
$color_t_body = $db[color_t_body];
}
$sql="update test_chat set user='$user', pass='$pass', bg ='$bg', banner='$banner', color_t='$color_t', t_menu='$t_menu', color_t_menu='$color_t_menu', t_body ='$t_body', color_t_body='$color_t_body' WHERE id=1";
$result = mysql_query($sql);
if($result) {
echo "<center>
<table border=\"1\" style=\"border-style:dotted; border-collapse: collapse; padding-left:4; padding-right:4; padding-top:1; padding-bottom:1\" bordercolor=\"#111111\" width=\"50%\" id=\"AutoNumber1\" height=\"138\">
<tr>
<td height=\"136\">
<center>
<font size=\"5\" color=\"#000080\">การแก้ไขข้อมูลสำเร็จ !!</font><br><br>
<font size=\"4\"><a href=\"manage_chat.php\">ตกลง</a></font>
</center>
</td>
</tr>
</table>
</center>";
}
else {
echo "<center>
<table border=\"1\" style=\"border-style:dotted; border-collapse: collapse; padding-left:4; padding-right:4; padding-top:1; padding-bottom:1\" bordercolor=\"#111111\" width=\"50%\" id=\"AutoNumber1\" height=\"138\">
<tr>
<td height=\"136\" bgcolor=\"#FFCCFF\">
<center>
<font size=\"5\" color=\"#000080\">การแก้ไขข้อมูลล้มเหลว !!</font><br><br>
<font size=\"4\"><a href=\"manage_chat.php\">ตกลง</a></font>
</center>
</td>
</tr>
</table>
</center>";
}
?>
ขอบพระคุณมากครับ
โอ
Tag : PHP, MySQL