|
 |
|
ขอสอบถามเรื่องการส่งค่าตัวแปร คะ คือตอนนี้หนูทำแบบสอบถาม แบ่งเปน 4 หน้าคือจะให้ ลุกค้ากรอกแบบฟอร์มจากหน้า 1 |
|
 |
|
|
 |
 |
|
ใช้ $_SESSION ก็ได้ครับ
เก็บเป็น Session ไว้ก่อน พอถึงหน้าสุดท้ายเอา Session นั้นไป Insert
ปล. อย่าลืมใส่ session_start(); ไว้บนสุด
Code (PHP)
<?php
session_start();
?>
<html>
<head>
<title></title>
Code (PHP)
$_SESSION['idcard'] = $_POST['idcard'];
https://www.thaicreate.com/php/php-session.html
รอผู้รู้ท่านต่อไป 
|
ประวัติการแก้ไข 2014-07-04 10:42:56 2014-07-04 10:43:38 2014-07-04 10:48:25
 |
 |
 |
 |
Date :
2014-07-04 10:40:25 |
By :
sabaitip |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอไม่ทำซะหน้าเดียวเลยะครับ แต่ไม่เป็นไรก็แล้วแต่ อัลกอริทึม ของแต่ละคนครับ
page1.php
Code (PHP)
<?php session_start(); ?>
<form method="post" action="page2.php">
ID Card No</label> <input name="idcard" type="text" /> </p>
<input type='submit' >
</form>
page2.php
Code (PHP)
<?php session_start();
$_SESSION['idcard']=$_POST['idcard'];
?>
<form method="post" action="page3.php">
<input name="Adress_no" type="text" /> <span class="val_phone"></span> </p>
<input type='submit' >
</form>
page3.php
Code (PHP)
<?php session_start();
$_SESSION['Adress_no']=$_POST['Adress_no'];
?>
<form method="post" action="page4.php">
<input name="a_degree" type="radio" value="m" /> ปริญญาเอก / Ph.D. Degree<br>
<input type='submit' >
</form>
page4.php
Code (PHP)
<?php session_start();
$_SESSION['a_degree']=$_POST['a_degree'];
?>
<form method="post" action="page5.php">
<input name="Movie" type="checkbox" value="Movie" /> ภาพยนตร์ / Movie<br>
<input type='submit' >
</form>
page5.php
Code (PHP)
<?php session_start();
echo $idcard=$_SESSION['idcard'];
echo "<br />", $Adress_no=$_SESSION['Adress_no'];
echo "<br />", $a_degree=$_SESSION['a_degree'];
echo "<br />", $Movie=$_POST['Movie'];
?>
ปล. ไม่ได้ตรวจเช็คเออเร่อร์
|
 |
 |
 |
 |
Date :
2014-07-04 10:49:05 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ Session ในการเก็บค่าซิครัช
หน้า 1
Code (PHP)
<?php
$idcard=$_POST[idcard];
echo "ID Card No<input name='idcard' type='text' />";
?>
หน้า 2
Code (PHP)
<?php
session_start();
$_SESSION['idcard']=$_POST[idcard];
echo "<input name='Adress_no' type='text' /> <span class="val_phone"></span>";
?>
Address ไม่มีการส่งมาจากหน้า 1 นะครับ ดังนั้นต้องสร้างแบบฟอร์มให้ก่อน
หน้า 3
Code (PHP)
<?php
session_start();
$_SESSION['Adress_no']=$_POST[Adress_no];
echo "<input name='a_degree' type='radio' value='m' /> ปริญญาเอก / Ph.D. Degree<br>
หน้า 4
Code (PHP)
<?php
session_start();
$_SESSION['a_degree']=$_POST['a_degree'];
<input name='Movie' type=;checkbox' value='Movie' /> ภาพยนตร์ / Movie<br>
?>
หน้า 5
Code (PHP)
<?php
session_start();
$_SESSION['Movie']=$_POST['Movie'];
?>
ข้อมูลทั้งหมดจะถูกเก็บไว้ที่ Session ของเซิร์ฟเวอร์จนกว่าจะปิด Browser ไปครับลองใช้คำสั่ง
Code (PHP)
print_r($_SESSION);
อย่าลืมใช้ session_start(); ทุกครั้งที่จะใช้งาน Session ครัช
ปล. คห.2 เอาไปใช้งานได้เลยนะลองดูครับ
|
ประวัติการแก้ไข 2014-07-04 10:56:42
 |
 |
 |
 |
Date :
2014-07-04 10:53:43 |
By :
soghband |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
page4.php
2. $_SESSION['a_degree']=$_POST['a_degree'];
แก้เป็น
Code (PHP)
$_SESSION['a_degree']=isset($_POST['a_degree'])? $_POST['a_degree'] : '[noSelect]';
page5.php
echo "<br />", $Movie=$_POST['Movie'];
แก้เป็น
Code (PHP)
echo "<br />", $Movie=$_POST['Movie'] || '[noCheck]';
|
 |
 |
 |
 |
Date :
2014-07-04 11:00:24 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|