|
 |
|
สอบถามการบันทึกแบบฟอร์มข้อมูลโดยไม่ต้องสร้างหน้าเอาไว้เซฟ |
|
 |
|
|
 |
 |
|
มีครับ ใช้ get+switch เอาก้อได้
ตัวอย่าง
Code (PHP)
<body>
<?
$member = $_GET['member'];
switch ($member){
case 'add' :
$name = $_POST['name'];
$sql = mysql_query ("insert into member (name) values ('$name')");
echo "บันทึกข้อมูลเรียบร้อย";
}
?>
<form action="?member=add">
ใส่ form กรอกข้อมูล
</form>
</body>
จริงๆแล้วสามารถ แสดง เพิ่ม ลบ แก้ไข ใน ไฟล์เดียวเลยก้อได้ครับ เพราะผมก้อใช้หลักการแบบนี้จะได้ไม่ต้องมีไฟล์เยอะๆให้รกตา 55
|
 |
 |
 |
 |
Date :
2013-12-22 14:27:11 |
By :
topza1412 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แค่ย้าย save_form.php มารวม form.php เท่านั้นเองครับ
โดยจะให้อยู่ก่อนแบบฟอร์ม หรือก่อน <html> ไปเลย
|
 |
 |
 |
 |
Date :
2013-12-22 22:49:23 |
By :
{Cyberman} |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดูครับอัลกอรึทึมก็ประมาณนี้เหละ
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<form method="post" action="">
<input type="submit" name="button" id="button" value="บันทึก" /><br>
<? if ($_POST) { echo "ใส่โค้ดINSERT INTO ตรงนี้เหละ"; } ?>
|
 |
 |
 |
 |
Date :
2013-12-23 21:33:28 |
By :
meannerss |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้ามันมีการตรวจสอบความถูกต้องด้วย ต้องใส่ switch case ตรงไหนบ้างครับ ได้ลองทดสอบมันเปลี่ยนเป็นอีกหน้า อยากให้มันขึ้นข้อความแจ้งข้างบนหน้าที่มีฟอร์มด้วย ต้องทำไงครับ
Code (PHP)
<html>
<head><meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>member</title>
</head>
<body>
<?
$member = $_GET['member'];
switch ($member){
case 'add' :
$user_reg=$_POST[user_reg];
$pass_reg=$_POST[pass_reg];
$name_ref=$_POST[name_reg];
$sex_reg=$_POST[sex_reg];
$email_reg=$_POST[email_reg];
$address_reg=$_POST[address_reg];
$date_reg=date("Y/m/d");
if ($user_reg=="" or $pass_reg=="" or $name_reg=="") {
echo "กรุณากรอกข้อมูลให้ครบ";
exit ();
}
include "connect.php";
$sql="select * from tb_member where username='$user_reg' ";
$result=mysql_db_query($dbname, $sql);
$num=mysql_num_rows($result);
if ($num<0) {
echo "username ซ้ำครับ";
}
$sql="insert into tb_member value (' ', '$user_reg', '$pass_reg', '$name_reg', '$sex_reg', '$email_reg', '$tel_reg', '$address_reg', '$date_reg') ";
$resut=mysql_db_query($dbname, $sql);
if ($result) {
echo " ข้อมูลของคุณถูกบันทึกเรียบร้อยแล้ว";
} else {
echo "ไม่สามารถบันทึกข้อมูลได้";
}
}
?>
<h1> : : Register : : </h1>
<form action="?member=add" method="post">
Username<br>
<input type="text" name="user_reg"><br>
Password<br>
<input type="password" name="pass_reg"><br>
ชื่อ - นามสกุล<br>
<input type="text" name="name_reg"><br>
เพศ<br>
<input type="radio" name="sex_reg" value="ชาย" checked>ชาย
<input type="radio" name="sex_reg" value="หญิง">หญิง<br>
อีเมล์<br>
<input type="text" name="email_reg"><br>
โทรศัพท์<br>
<input type="text" name="telephon_reg" size="26"><br>
ที่อยู่<br>
<textarea name="address_reg" cols="35" rows="3"></textarea><br>
<input type="submit" value="ตกลง">
<input type="reset" value="ล้าง">
</form>
</body>
</html>
|
 |
 |
 |
 |
Date :
2013-12-24 14:39:32 |
By :
เต้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดูแบบนี้ครับ
<html>
<head><meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>member</title>
</head>
<body>
<?
if(isset($_GET['member'])){
///////////////////////// ถ้ามีการส่งพารามิเตอร์ member ////////////////////////////////
$member = $_GET['member'];
switch ($member){
case 'add' :
$user_reg=$_POST[user_reg];
$pass_reg=$_POST[pass_reg];
$name_ref=$_POST[name_reg];
$sex_reg=$_POST[sex_reg];
$email_reg=$_POST[email_reg];
$address_reg=$_POST[address_reg];
$date_reg=date("Y/m/d");
if ($user_reg=="" or $pass_reg=="" or $name_reg=="") {
echo "กรุณากรอกข้อมูลให้ครบ";
exit ();
}
include "connect.php";
$sql="select * from tb_member where username='$user_reg' ";
$result=mysql_db_query($dbname, $sql);
$num=mysql_num_rows($result);
if ($num<0) {
echo "username ซ้ำครับ";
}
$sql="insert into tb_member value (' ', '$user_reg', '$pass_reg', '$name_reg', '$sex_reg', '$email_reg', '$tel_reg', '$address_reg', '$date_reg') ";
$resut=mysql_db_query($dbname, $sql);
if ($result) {
echo " ข้อมูลของคุณถูกบันทึกเรียบร้อยแล้ว";
} else {
echo "ไม่สามารถบันทึกข้อมูลได้";
}
}
}///////////////////////////////////// end-if(isset($_GET['member'])) ///////////////////////////////////////
?>
<h1> : : Register : : </h1>
<form action="?member=add" method="post">
Username<br>
<input type="text" name="user_reg"><br>
Password<br>
<input type="password" name="pass_reg"><br>
ชื่อ - นามสกุล<br>
<input type="text" name="name_reg"><br>
เพศ<br>
<input type="radio" name="sex_reg" value="ชาย" checked>ชาย
<input type="radio" name="sex_reg" value="หญิง">หญิง<br>
อีเมล์<br>
<input type="text" name="email_reg"><br>
โทรศัพท์<br>
<input type="text" name="telephon_reg" size="26"><br>
ที่อยู่<br>
<textarea name="address_reg" cols="35" rows="3"></textarea><br>
<input type="submit" value="ตกลง">
<input type="reset" value="ล้าง">
</form>
</body>
</html>
|
 |
 |
 |
 |
Date :
2013-12-24 16:47:41 |
By :
sakuraei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|