form « แลกเปลี่ยนเรียนรู้:km tool

archive page

คำสำคัญ ‘form’

ปรับปรุงฟอร์มตามรหัสผู้ใช้ด้วย PHP รุ่น 1

โดย บุรินทร์ รุจจนพันธุ์ เมื่อ Tuesday, June 28th, 2011

28 มิ.ย.54 มีโอกาสพัฒนาโปรแกรม เรียกว่า โปรแกรมรุ่นหนึ่งสำหรับสร้างฟอร์มปรับข้อมูลตามรหัสผู้ใช้ เขียนด้วย PHP4 บน IIS6 สำหรับระบบ TQF มี 4 โปรแกรม คือ
1. โปรแกรมรับรหัสผู้ใช้ (index.php)
2. โปรแกรมตรวจรหัส และแสดงข้อมูลในฟอร์ม (user.php)
3. โปรแกรมปรับปรุงข้อมูล (update.php)
4. โปรแกรมออกจากระบบ (logout.php)

<form action=”user.php” method=”post”>
<input name=”fuser” value=”">
<input name=”fpasswd” type=password value=”">
<input type=”submit” value=”เข้าใช้ระบบ”>
</form>

<?
session_start();
$mysql_db = “tqf”;
$mysql_user = “root”;
$mysql_password = “yourname”;
if (isset($_REQUEST['fuser']) &&
$_REQUEST['fuser'] == “myname” && $_REQUEST['fpasswd'] == “mypass”) {
$_SESSION['suser'] = $_REQUEST['fuser'];
}
if (!isset($_SESSION['suser'])) header(“Location: index.php”);
// ====
$query    = “select * from tqf1″;
echo “<form action=update.php method=post>”;
$connect = mysql_connect(“localhost”, $mysql_user , $mysql_password);
mysql_query(“set names tis620″);
$result = mysql_db_query($mysql_db,$query);
if ($result) {
while ($object = mysql_fetch_object($result)) {
echo ‘<textarea name=t101 rows=5 cols=80>’. $object->t101 . “</textarea><br />”;
echo ‘<textarea name=t102 rows=5 cols=80>’. $object->t102 . “</textarea><br />”;
echo ‘<textarea name=t103 rows=5 cols=80>’. $object->t103 . “</textarea><br />”;
echo ‘<textarea name=t104 rows=5 cols=80>’. $object->t104 . “</textarea><br />”;
echo ‘<textarea name=t105 rows=5 cols=80>’. $object->t105 . “</textarea><br />”;
}
echo “<br/><input type=submit value=’ปรับปรุง’></form>”;
}
mysql_close($connect);
?>
<a href=logout.php>logout</a>

<?
session_start();
$mysql_db = “tqf”;
$mysql_user = “root”;
$mysql_password = “yourname”;
if (isset($_SESSION['suser'])) {
$query    = “update tqf1 set
t101=’”. $_POST["t101"] .”‘ ,
t102=’”. $_POST["t102"] .”‘ ,
t103=’”. $_POST["t103"] .”‘ ,
t104=’”. $_POST["t104"] .”‘ ,
t105=’”. $_POST["t105"] .”‘
where user =’”. $_SESSION['suser'] . “‘”;
$connect = mysql_connect(“localhost”, $mysql_user , $mysql_password);
mysql_query(“set names tis620″);
$result = mysql_db_query($mysql_db,$query);
echo $query;
mysql_close($connect);
header(“Location: user.php”);
}
header(“Location: index.php”);
?>

<?
session_start();
session_destroy();
header(“Location: user.php”);
?>


ทดสอบ ajax กับ mysql พบปัญหาคำว่า form ผ่าน div

โดย บุรินทร์ รุจจนพันธุ์ เมื่อ Tuesday, September 14th, 2010
14 ก.ย.53 วันนี้ ปิดงานไม่ลง เพราะทดสอบการใช้ mysql update ในฟอร์มแบบ interactive แล้วทำงานร่วมกับ ajax กว่าจะพบว่า ส่งผลที่มีคำว่า form เข้าผ่าน div แล้วเป็นเหตุให้ไม่แสดงผล ก็ดึกพอดี จะแก้โปรแกรมต้นโค้ด 9137 ก็ไม่มีสมาธิซะแล้ว .. พักยกก่อนครับวันนี้ พบเหตุของปัญหาแล้วเพียงแต่ไม่ได้ปรับปรุงใหม่ทั้งชุด ให้ทำงานร่วมกับ ajax ที่สมบูรณ์แล้ว up เข้า thaiall.com/ajax เท่านั้น
ต้นโค้ดจาก http://www.thaiall.com/perlphpasp/source.pl?9137