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

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”);
?>

Author: บุรินทร์ รุจจนพันธุ์

I am Lecturer, Developer, Researcher, Columnist, Writer, Photographer, and Webmaster - L@mpang man

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.