Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,028

HOME > PHP > PHP Forum > PHP สร้าง session เก็บค่าจาก form ไม่ได้ครับมันไม่แสดงค่า



 

PHP สร้าง session เก็บค่าจาก form ไม่ได้ครับมันไม่แสดงค่า

 



Topic : 127256



โพสกระทู้ ( 190 )
บทความ ( 0 )



สถานะออฟไลน์




ผมสร้างฟอร์ม checkout ตะกร้าสินค้าโดย ถ้า user มีการ login ให้ดูข้อมูลในดาต้าเบสมาใส่ใน form แต่ถ้าไม่ได้ login ก็ต้องกรอก captcha และถ้ากรอกผิดให้แสดงข้อมูลที่เคยพิมไว้ออกมาที่ form

ผมสร้างเว็บหลักหน้าเดียวคือ checkout.php แต่ให้ include หน้าต่างๆเข้ามาตาม step
Quote:
step 1 คือ shippingAndPaymentInfo.php กรอกข้อมูล
step 2 คือ checkoutConfirmation.php ยืนยันข้อมูล ไม่มี form ให้กรอก
step 3 คือบันทึกข้อมูล


Code (PHP)
if(!((md5((isset($_POST['captcha'])?$_POST['captcha']:"")) == $_SESSION['captchaKey']) || (isset($_SESSION['plaincart_customer_id']))))  



ไว้ที่ step 3 เพื่อเวลากรอก captcha ผิดจะได้ไม่ต้องกรอกข้อมูลใหม่ แต่ปัญหาคือพอกรอกผิดสั่ง header มาที่ไฟล์ checkoutConfirmation.php มันจะขึ้นหน้าว่างๆไม่มีไรเลย

ผมจึงเปลี่ยนเป็นนำ captcha ไว้ที่หน้า step 1 shippingAndPaymentInfo.php แล้วตรวจสอบที่ step 2 ดังนี้ครับ

โค้ดหน้า checkout.php

Code (PHP)
if (isCartEmpty()) {
	// หากตะกร้าสินค้าว่าง ก็ให้กับไปยัง cart.php
	header('Location: cart.php');
} else if (isset($_GET['step']) && (int)$_GET['step'] > 0 && (int)$_GET['step'] <= 3) {
	$step = (int)$_GET['step'];   //ตรวจสอบว่าเป็น step อะไร 1,2 หรือ 3

	$includeFile = '';

	if ($step == 1) {	                                //หากเป็นขั้นตอนแรก

		$includeFile = 'shippingAndPaymentInfo.php';
		$pageTitle   = 'Checkout - Step 1 of 2';

	} else if ($step == 2) {	                       //เมื่อเป็นขั้นตอนที่ 2
			 
			// Use captcha
			if(!((md5((isset($_POST['captcha'])?$_POST['captcha']:"")) == $_SESSION['captchaKey']) || (isset($_SESSION['plaincart_customer_id'])))){	

/********************** เก็บค่าลงใน session **************************/
		
			session_start();
			$_session['txtShippingFirstName'] = $_POST['txtShippingFirstName'];
			$_session['txtShippingLastName'] = $_POST['txtShippingLastName'];
			$_session['txtShippingEmail'] = $_POST['txtShippingEmail'];
			$_session['txtShippingAddress1'] = $_POST['txtShippingAddress1'];
			$_session['txtShippingAddress2'] = $_POST['txtShippingAddress2'];
			$_session['txtShippingPhone'] = $_POST['txtShippingPhone'];
			$_session['txtShippingCity'] = $_POST['txtShippingCity'];
			$_session['txtShippingState'] = $_POST['txtShippingState'];
			$_session['txtShippingPostalCode'] = $_POST['txtShippingPostalCode'];
			
			setError("กรุณากรอก CAPTCHA ให้ถูกต้องด้วยครับ");
			header("Location: checkout.php?step=1"); 
				
			}else{
				$includeFile = 'checkoutConfirmation.php';
				$pageTitle   = 'Checkout - Step 2 of 2';
			}
			
				/*$includeFile = 'checkoutConfirmation.php';
				$pageTitle   = 'Checkout - Step 2 of 2';  */
				
	} else if ($step == 3) {	                      //หรือเป็นขั้นตอนที่ 3
	
		$orderId     = saveOrder();
		$orderAmount = getOrderAmount($orderId);
		
		$_SESSION['orderId'] = $orderId;	//เก็บรหัสการสั่งสินค้าเข้า session
		

			header('Location: success.php');
			exit;
	
	}
} else {
	//ถ้าไม่มีการส่งค่า step ก็ให้กลับไปยังหน้า index.php 
	header('Location: index.php');
}



หน้า shippingAndPaymentInfo.php มี form แบบนี้ครับ

Code (PHP)
<?php

//ตรวจสอบว่าได้ล็อกอินในฐานะสมาชิกหรือไม่

if(!isset($_SESSION['plaincart_customer_id'])) {
	?>
<div class="panel panel-info">
	<div class="panel-heading">สมาชิก</div>
  	<div class="panel-body">
            ถ้าท่านเป็นสมาชิก <a href="<?php echo WEB_ROOT.'login.php?cartURL=step1';?>">คลิกที่นี่</a> ข้อมูลของท่านจะถูกนำมาใส่ลงแบบฟอร์มข้างล่างโดยอัตโนมัติ 
  	</div>
</div>

	<?php
} else {			//ถ้าเป็นสมาชิก ดึงข้อมูลสมาชิกมาเก็บไว้ที่ตัวแปร $userProfile
    $userProfile = getCustomerProfile(); 
	extract($userProfile);
}

   //นำข้อมูลของสมาชิกเก็บเข้าตัวแปร
    $customerFirstName = (isset($user_first_name))?$user_first_name:'';
    $customerLastName = (isset($user_last_name))?$user_last_name:'';
    $customerEmail = (isset($user_email))?$user_email:'';
    $customerAddress = (isset($user_address))?$user_address:'';
    $customerPhone = (isset($user_phone))?$user_phone:'';
    $customerCity = (isset($user_city))?$user_city:'';
    $customerState = (isset($user_state))?$user_state:'';
    $customerPostalCode = (isset($user_postal_code))?$user_postal_code:'';
	$customerUserId = (isset($user_id))?$user_id:'';
	

/*************************  โค้ดส่วนนี้เพิ่งเพิ่มเข้าไปเพื่อแสดงค่าใน session *********************************/

if(isset($_session['txtShippingFirstName'])?$_session['txtShippingFirstName']:""){
			$customerFirstName = $_session['txtShippingFirstName'];
			$customerLastName = $_session['txtShippingLastName'];
			$customerEmail = $_session['txtShippingEmail'];
			$customerAddress = $_session['txtShippingAddress1'];
			//$_session['txtShippingAddress2']
			$customerPhone = $_session['txtShippingPhone'];
			$customerCity = $_session['txtShippingCity'];
			$customerState = $_session['txtShippingState'];
			$customerPostalCode = $_session['txtShippingPostalCode'];
	
}


?>
<!-- แบบฟอร์มสำหรับผู้ซื้อสินค้า -->
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?step=2" method="post" name="frmCheckout" id="frmCheckout" onSubmit="return checkShippingAndPaymentInfo();">
<div class="panel panel-info">
  <div class="panel-heading">ข้อมูลของผู้รับสินค้า</div>
  <div class="panel-body">

    <table width="550" border="0" align="center" cellpadding="5" cellspacing="1" class="table">

        <tr> 
            <td width="200" class="">ชื่อ&nbsp;<span class="label label-warning">ต้องการ</span></td>
            <td class=""><input name="txtShippingFirstName" type="text" class="box" id="txtShippingFirstName" size="32" maxlength="50" value="<?php echo $customerFirstName; ?>"></td>
        </tr>
        <tr> 
            <td width="200" class="">นามสกุล&nbsp;<span class="label label-warning">ต้องการ</span></td>
            <td class=""><input name="txtShippingLastName" type="text" class="box" id="txtShippingLastName" size="32" maxlength="50" value="<?php echo $customerLastName; ?>"></td>
        </tr>
        <tr> 
            <td width="200" class="">Email&nbsp;<span class="label label-warning">ต้องการ</span></td>
            <td class=""><input name="txtShippingEmail" type="text" class="box" id="txtShippingEmail" size="32" maxlength="50" value="<?php echo $customerEmail; ?>"></td>
        </tr>
        <tr> 
            <td width="" class="">ที่อยู่&nbsp;<span class="label label-warning">ต้องการ</span></td>
            <td class=""><input name="txtShippingAddress1" type="text" class="box" id="txtShippingAddress1" size="32" maxlength="100" value="<?php echo $customerAddress; ?>"></td>
        </tr>
        <tr> 
            <td width="" class="">ที่อยู่เพิ่มเติม</td>
            <td class=""><input name="txtShippingAddress2" type="text" class="box" id="txtShippingAddress2" size="32" maxlength="100"></td>
        </tr>
        <tr> 
            <td width="" class="">เบอร์โทรศัพท์&nbsp;<span class="label label-warning">ต้องการ</span></td>
            <td class="content"><input name="txtShippingPhone" type="text" class="box" id="txtShippingPhone" size="32" maxlength="32" value="<?php echo $customerPhone; ?>"></td>
        </tr>

        <tr> 
            <td width="" class="">เขต/อำเภอ&nbsp;<span class="label label-warning">ต้องการ</span></td>
            <td class="content"><input name="txtShippingCity" type="text" class="box" id="txtShippingCity" size="32" maxlength="32" value="<?php echo $customerCity; ?>"></td>
        </tr>
        <tr> 
            <td width="" class="">จังหวัด&nbsp;<span class="label label-warning">ต้องการ</span></td>
            <td class="content"><input name="txtShippingState" type="text" class="box" id="txtShippingState" size="32" maxlength="32" value="<?php echo $customerState; ?>"></td>
        </tr>
        <tr> 
            <td width="150" class="">รหัสไปรษณีย์&nbsp;<span class="label label-warning">ต้องการ</span></td>
            <td class=""><input name="txtShippingPostalCode" type="text" class="box" id="txtShippingPostalCode" size="10" maxlength="10" value="<?php echo $customerPostalCode; ?>"></td>
        </tr>
    </table>
	</div>
</div>    
    

<div class="panel panel-info">
  <div class="panel-heading">ข้อมูลของผู้ชำระค่าสินค้า</div>
  <div class="panel-body">
    <table width="550" border="0" align="center" cellpadding="5" cellspacing="1" class="table">
        <tr class=""> 
        	<td>&nbsp;</td>
            <td><input type="checkbox" name="chkSame" id="chkSame" value="checkbox" onClick="setPaymentInfo(this.checked);"> 
                <label for="chkSame" style="cursor:pointer">ใช้ข้อมูลเดียวกับผู้รับสินค้าด้านบน</label></td>
        </tr>
        <tr> 
            <td width="200" class="">ชื่อ&nbsp;<span class="label label-warning">ต้องการ</span></td>
            <td class=""><input name="txtPaymentFirstName" type="text" class="box" id="txtPaymentFirstName" size="32" maxlength="50"></td>
        </tr>
        <tr> 
            <td width="200" class="">นามสกุล&nbsp;<span class="label label-warning">ต้องการ</span></td>
            <td class=""><input name="txtPaymentLastName" type="text" class="box" id="txtPaymentLastName" size="32" maxlength="50"></td>
        </tr>
        <tr> 
            <td width="150" class="">Email&nbsp;<span class="label label-warning">ต้องการ</span></td>
            <td class=""><input name="txtPaymentEmail" type="text" class="box" id="txtPaymentEmail" size="32" maxlength="50"></td>
        </tr>
        <tr> 
            <td width="150" class="">ที่อยู่&nbsp;<span class="label label-warning">ต้องการ</span></td>
            <td class=""><input name="txtPaymentAddress1" type="text" class="box" id="txtPaymentAddress1" size="32" maxlength="100"></td>
        </tr>
        <tr> 
            <td width="150" class="">ที่อยู่เพิ่มเติม</td>
            <td class=""><input name="txtPaymentAddress2" type="text" class="box" id="txtPaymentAddress2" size="32" maxlength="100"></td>
        </tr>
        <tr> 
            <td width="150" class="">เบอร์โทรศัพท์&nbsp;<span class="label label-warning">ต้องการ</span></td>
            <td class=""><input name="txtPaymentPhone" type="text" class="box" id="txtPaymentPhone" size="32" maxlength="32"></td>
        </tr>
        <tr> 
            <td width="150" class="">เขต/อำเภอ&nbsp;<span class="label label-warning">ต้องการ</span></td>
            <td class=""><input name="txtPaymentCity" type="text" class="box" id="txtPaymentCity" size="32" maxlength="32"></td>
        </tr>
        <tr> 
            <td width="150" class="">จังหวัด&nbsp;<span class="label label-warning">ต้องการ</span></td>
            <td class=""><input name="txtPaymentState" type="text" class="box" id="txtPaymentState" size="32" maxlength="32"></td>
        </tr>
        <tr> 
            <td width="150" class="">รหัสไปรษณีย์&nbsp;<span class="label label-warning">ต้องการ</span></td>
            <td class=""><input name="txtPaymentPostalCode" type="text" class="box" id="txtPaymentPostalCode" size="10" maxlength="10"></td>
        </tr>
    </table>
  </div>
</div>
    
    <table width="550" border="0" align="center" cellpadding="5" cellspacing="1" class="table">
      <tr>
        <td width="150" class="">วิธีชำระเงิน </td>
        <td class="">
        <input name="optPayment" type="radio" value="cod" id="optCod" checked="checked"/>
        <label for="optCod" style="cursor:pointer">โอนเงินผ่านธนาคาร</label>
        <input name="optPayment" type="radio" id="optPaypal" value="paypal" />
        <label for="optPaypal" style="cursor:pointer">Paypal</label>
        </td>
      </tr>
                     <?php
              
        if(!isset($_SESSION['plaincart_customer_id'])) {
        ?>
        <tr>
          			<td width="150" class="">กรอกรหัสที่เห็นในภาพ <span class="label label-warning">ต้องการ</span></td>
  					<td>
     				<div>
        				<img src="<?php echo 'include/captcha/captcha.php'; ?>" border="0" />
        				<input type="text" name="captcha" id="captcha" class="box">
     				</div>
   					</td>
        
        <tr/>
        <?php
		}
		?>
    </table>
    
<div class="panel panel-info">
  <div class="panel-body"> 
    <p align="center"> 
    <input name="user_id" type="hidden" value="<?php echo $customerUserId; ?>" />
        <input class="btn btn-primary" name="btnStep1" type="submit" id="btnStep1" value="ดำเนินการ &gt;&gt;">
    </p>
   </div>
</div>
</form>



หน้าอื่นๆไม่ได้แก้ไรเลยครับ หน้า checkoutConfirmation.php ยังเหมือนเดิมแค่ไว้แสดงข้อมูลแบบนี้ครับไม่ได้แก้ไร

Code (PHP)
<?php
//ตรวจสอบว่ามาจาก step=1 และต้องแน่ใจว่าไม่มีการเข้ามายังหน้านี้โดยตรง
if (!defined('WEB_ROOT')
    || !isset($_GET['step']) || (int)$_GET['step'] != 2
	|| $_SERVER['HTTP_REFERER'] != 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?step=1') {
	exit;
}

$errorMessage = '&nbsp;';

/* ทำให้แน่ใจว่า ข้อมูลในส่วนที่ต้องการต้องไม่เป็นค่าว่าง */
$requiredField = array('txtShippingFirstName', 'txtShippingLastName', 'txtShippingEmail', 'txtShippingAddress1', 'txtShippingPhone', 'txtShippingState',  'txtShippingCity', 'txtShippingPostalCode',
                       'txtPaymentFirstName', 'txtPaymentLastName', 'txtPaymentEmail','txtPaymentAddress1', 'txtPaymentPhone', 'txtPaymentState', 'txtPaymentCity', 'txtPaymentPostalCode');
					   
if (!checkRequiredPost($requiredField)) {
	$errorMessage = 'ผิดพลาด ข้อมูลไม่สมบูรณ์';
}
					   

$cartContent = getCartContent();	//ดึงข้อมูลจากตะกร้าสินค้ามาเก็บเข้าตัวแปร $cartContent

?>
<table width="100%" border="0" align="center" cellpadding="10" cellspacing="0">
    <tr> 
        <td><h3>ขั้นตอนที่ 2 จาก 3 : ยืนยันการสั่งสินค้า</h3></td>
    </tr>
</table>
<div id="errorMessage" alert alert-danger><?php echo $errorMessage; ?></div>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?step=3" method="post" name="frmCheckout" id="frmCheckout">

<div class="panel panel-info">
  <div class="panel-heading">รายการสินค้าที่ท่านได้สั่งไว้กับทางร้าน</div>
  <div class="panel-body"> 
    <table width="550" border="0" align="center" cellpadding="5" cellspacing="1" class="table">
        <tr class="active"> 
            <td>รายการ</td>
            <td align="right">ราคาสินค้า</td>
            <td align="right">รวมย่อย</td>
        </tr>
        <?php
$numItem  = count($cartContent);
$subTotal = 0;
$subShipping = 0;
for ($i = 0; $i < $numItem; $i++) {
	extract($cartContent[$i]);
	$subTotal += $pd_price * $ct_qty;
	$subShipping += $pd_shipping * $ct_qty;
?>
        <tr class=""> 
            <td class=""><?php echo "<span class=\"label label-danger\" style=\"font-size:0.9em;\">$ct_qty</span> x $pd_name"; ?></td>
            <td align="right"><?php echo displayAmount($pd_price); ?></td>
            <td align="right"><?php echo displayAmount($ct_qty * $pd_price); ?></td>
        </tr>
        <?php
}

$shippingCost = $shopConfig['shippingCost'] + $subShipping;

?>
        <tr class=""> 
            <td colspan="2" align="right">รวม</td>
            <td align="right"><?php echo displayAmount($subTotal); ?></td>
        </tr>
        <tr class=""> 
            <td colspan="2" align="right">ค่าขนส่ง</td>
            <td align="right"><?php echo displayAmount($shippingCost); ?></td>
        </tr>
        <tr class="active"> 
            <td colspan="2" align="right">รวมสุทธิ</td>
            <td align="right"><strong style="font-size:1.1em;"><?php echo displayAmount($subTotal + $shippingCost); ?></strong></td>
        </tr>
    </table>
    </div>
</div>
<div class="panel panel-info">
  <div class="panel-heading">ข้อมูลของผู้รับสินค้า</div>
  <div class="panel-body">  
  
    <table width="100%" border="0" align="center" cellpadding="5" cellspacing="1" class="table">
        <tr> 
            <td width="150" class="">ชื่อ</td>
            <td class=""><?php echo $_POST['txtShippingFirstName']; ?>
                <input name="hidShippingFirstName" type="hidden" id="hidShippingFirstName" value="<?php echo $_POST['txtShippingFirstName']; ?>"></td>
        </tr>
        <tr> 
            <td width="150" class="">นามสกุล</td>
            <td class=""><?php echo $_POST['txtShippingLastName']; ?>
                <input name="hidShippingLastName" type="hidden" id="hidShippingLastName" value="<?php echo $_POST['txtShippingLastName']; ?>"></td>
        </tr>
        <tr> 
            <td width="150" class="">อีเมล</td>
            <td class=""><?php echo $_POST['txtShippingEmail']; ?>
                <input name="hidShippingEmail" type="hidden" id="hidShippingEmail" value="<?php echo $_POST['txtShippingEmail']; ?>"></td>
        </tr>
        <tr> 
            <td width="150" class="">ที่อยู่</td>
            <td class=""><?php echo $_POST['txtShippingAddress1']; ?>
                <input name="hidShippingAddress1" type="hidden" id="hidShippingAddress1" value="<?php echo $_POST['txtShippingAddress1']; ?>"></td>
        </tr>
        <tr> 
            <td width="150" class="">ที่อยู่เพิ่มเติม</td>
            <td class=""><?php echo $_POST['txtShippingAddress2']; ?>
                <input name="hidShippingAddress2" type="hidden" id="hidShippingAddress2" value="<?php echo $_POST['txtShippingAddress2']; ?>"></td>
        </tr>
        <tr> 
            <td width="150" class="">โทรศัพท์</td>
            <td class=""><?php echo $_POST['txtShippingPhone'];  ?>
                <input name="hidShippingPhone" type="hidden" id="hidShippingPhone" value="<?php echo $_POST['txtShippingPhone']; ?>"></td>
        </tr>
        <tr> 
            <td width="150" class="">เขต / อำเภอ</td>
            <td class=""><?php echo $_POST['txtShippingState']; ?> <input name="hidShippingState" type="hidden" id="hidShippingState" value="<?php echo $_POST['txtShippingState']; ?>" ></td>
        </tr>
        <tr> 
            <td width="150" class="">จังหวัด</td>
            <td class=""><?php echo $_POST['txtShippingCity']; ?>
                <input name="hidShippingCity" type="hidden" id="hidShippingCity" value="<?php echo $_POST['txtShippingCity']; ?>" ></td>
        </tr>
        <tr> 
            <td width="150" class="">รหัสไปรษณีย์</td>
            <td class=""><?php echo $_POST['txtShippingPostalCode']; ?>
                <input name="hidShippingPostalCode" type="hidden" id="hidShippingPostalCode" value="<?php echo $_POST['txtShippingPostalCode']; ?>"></td>
        </tr>
    </table>
    </div>
</div>

<div class="panel panel-info">
  <div class="panel-heading">ข้อมูลผู้ชำระสินค้า</div>
  <div class="panel-body"> 
  
    <table width="100%" border="0" align="center" cellpadding="5" cellspacing="1" class="table">
        <tr> 
            <td width="150" class="">ชื่อ</td>
            <td class=""><?php echo $_POST['txtPaymentFirstName']; ?>
                <input name="hidPaymentFirstName" type="hidden" id="hidPaymentFirstName" value="<?php echo $_POST['txtPaymentFirstName']; ?>"></td>
        </tr>
        <tr> 
            <td width="150" class="">นามสกุล</td>
            <td class=""><?php echo $_POST['txtPaymentLastName']; ?>
                <input name="hidPaymentLastName" type="hidden" id="hidPaymentLastName" value="<?php echo $_POST['txtPaymentLastName']; ?>"></td>
        </tr>
        <tr> 
            <td width="150" class="">อีเมล</td>
            <td class=""><?php echo $_POST['txtPaymentEmail']; ?>
                <input name="hidPaymentEmail" type="hidden" id="hidPaymentEmail" value="<?php echo $_POST['txtPaymentEmail']; ?>"></td>
        </tr>
        <tr> 
            <td width="150" class="">ที่อยู่</td>
            <td class=""><?php echo $_POST['txtPaymentAddress1']; ?>
                <input name="hidPaymentAddress1" type="hidden" id="hidPaymentAddress1" value="<?php echo $_POST['txtPaymentAddress1']; ?>"></td>
        </tr>
        <tr> 
            <td width="150" class="">ที่อยู่เพิ่มเติม</td>
            <td class=""><?php echo $_POST['txtPaymentAddress2']; ?> <input name="hidPaymentAddress2" type="hidden" id="hidPaymentAddress2" value="<?php echo $_POST['txtPaymentAddress2']; ?>"> 
            </td>
        </tr>
        <tr> 
            <td width="150" class="">เบอร์โทรศัพท์</td>
            <td class=""><?php echo $_POST['txtPaymentPhone'];  ?> <input name="hidPaymentPhone" type="hidden" id="hidPaymentPhone" value="<?php echo $_POST['txtPaymentPhone']; ?>"></td>
        </tr>
        <tr> 
            <td width="150" class="">อำเภอ/เขต</td>
            <td class=""><?php echo $_POST['txtPaymentState']; ?> <input name="hidPaymentState" type="hidden" id="hidPaymentState" value="<?php echo $_POST['txtPaymentState']; ?>" ></td>
        </tr>
        <tr> 
            <td width="150" class="">จังหวัด</td>
            <td class=""><?php echo $_POST['txtPaymentCity']; ?>
                <input name="hidPaymentCity" type="hidden" id="hidPaymentCity" value="<?php echo $_POST['txtPaymentCity']; ?>"></td>
        </tr>
        <tr> 
            <td width="150" class="">รหัสไปรษณีย์</td>
            <td class=""><?php echo $_POST['txtPaymentPostalCode']; ?>
                <input name="hidPaymentPostalCode" type="hidden" id="hidPaymentPostalCode" value="<?php echo $_POST['txtPaymentPostalCode']; ?>"></td>
        </tr>
    </table>
    </div>
</div>    

<div class="panel panel-info">
  <div class="panel-heading">วิธีชำระเงิน</div>
  <div class="panel-body"> 

    <table border="0" align="center" cellpadding="5" cellspacing="1" class="table">
      <tr>
        <td class=""><?php echo $_POST['optPayment'] == 'paypal' ? 'Paypal' : 'โอนเงินผ่านธนาคาร'; ?>
          <input name="hidPaymentMethod" type="hidden" id="hidPaymentMethod" value="<?php echo $_POST['optPayment']; ?>" />
        </tr>
     
    </table>
   </div>
</div>

<div class="panel panel-info">
  <div class="panel-body"> 
  		<div align="center"> 

        <input name="hidUserId" type="hidden" id="hidUserId" value="<?php echo $_POST['user_id']; ?>">
        
        <input name="btnBack" type="button" id="btnBack" value="&lt;&lt; แก้ไขข้อมูลผู้สั่ง/ผู้รับสินค้า" onClick="window.location.href='checkout.php?step=1';" class="btn btn-primary">
        &nbsp;&nbsp; 
        <input name="btnConfirm" type="submit" id="btnConfirm" value="ยืนยันการสั่งสินค้า &gt;&gt;" class="btn btn-primary">
   		</div>
   </div>
</div>

</form>



พอกรอก captcha ผิดมันจะไป step 1 shippingAndPaymentInfo.php แต่ข้อมูลใน session ไม่แสดงครับ ข้อมูลใน form หายหมด



Tag : PHP









ประวัติการแก้ไข
2017-04-18 21:49:58
2017-04-18 21:51:03
2017-04-18 21:52:22
2017-04-18 23:05:30
2017-04-18 23:10:10
2017-04-18 23:10:56
2017-04-18 23:11:45
2017-04-19 09:09:54
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2017-04-18 21:48:19 By : mmc01 View : 2691 Reply : 8
 

 

No. 1



โพสกระทู้ ( 5,105 )
บทความ ( 4 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์


อย่างน้อย เอา session_start(); ไว้บนสุด ของบรรทัด
ไม่จำเป็นต้องผ่านเงื่อนไขแล้วจึงประกาศ session_start(); ครับ

และรบกวนเอา code ใส่แท็ก php ครับ ใส่แท็กอื่นๆ มันอ่านยาก
ใส่แท็ก php มันจะอ่านง่ายมีสีและบรรทัดครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-04-18 21:53:02 By : apisitp
 


 

No. 2



โพสกระทู้ ( 190 )
บทความ ( 0 )



สถานะออฟไลน์


session start ไว้บนสุดแล้วแต่มัน error ครับมีการเรียก session start แล้วตอนใส่ข้อมูลลงในตะกร้าสินค้ามันก็เลย error แบบนี้ครับ
Quote:
Notice: A session had already been started - ignoring session_start() in C:\xampp\htdocs\shop\library\config.php on line 7

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-04-18 23:08:02 By : mmc01
 

 

No. 3



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ลอง Save ไฟล์ให้เป็นแบบ UTF-8 (Without-BOM) ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-04-19 11:41:28 By : mr.win
 


 

No. 4



โพสกระทู้ ( 204 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

ลองใส่
Code (PHP)
if(isset($_SESSION['ชื่อ session'])) ได้ไหมครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-04-19 16:17:03 By : Pla2todkrob
 


 

No. 5



โพสกระทู้ ( 190 )
บทความ ( 0 )



สถานะออฟไลน์


ลอง save เป็น UTF-8 (Without-BOM) แล้วยังเหมือนเดิมครับ ถ้าพิมพ์ captcha ผิด form ก็ไม่แสดงอะไรเลยครับ



isset ผมใส่ไว้หน้า shippingAndPaymentInfo.php แล้วแบบนี้ครับ คือถ้ามี $_session['txtShippingFirstName'] ให้กำหนดค่าลงในตัวแปร

Code (PHP)
if(isset($_session['txtShippingFirstName'])?$_session['txtShippingFirstName']:""){


ยังเหมือนเดิมเลยครับไม่รู้ว่าทำผิดตรงไหน ตอนเก็บข้อมูลในตะกร้าสินค้า session ก็ใช้ได้ปกติครับ


ประวัติการแก้ไข
2017-04-19 22:19:13
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-04-19 22:18:17 By : mmc01
 


 

No. 6

Guest


if(isset($_session['txtShippingFirstName'])){

}
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-04-19 23:31:41 By : [email protected]
 


 

No. 7



โพสกระทู้ ( 190 )
บทความ ( 0 )



สถานะออฟไลน์


ยังเหมือนเดิมเหมือนกันครับ ไม่แสดงข้อมูลใน form ถ้ากรอก captcha ผิดครับ

Code (PHP)
if(isset($_session['txtShippingFirstName'])){
			$customerFirstName = $_session['txtShippingFirstName'];
			$customerLastName = $_session['txtShippingLastName'];
			$customerEmail = $_session['txtShippingEmail'];
			$customerAddress = $_session['txtShippingAddress1'];
			//$_session['txtShippingAddress2']
			$customerPhone = $_session['txtShippingPhone'];
			$customerCity = $_session['txtShippingCity'];
			$customerState = $_session['txtShippingState'];
			$customerPostalCode = $_session['txtShippingPostalCode'];
}

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-04-19 23:56:09 By : mmc01
 


 

No. 8



โพสกระทู้ ( 190 )
บทความ ( 0 )



สถานะออฟไลน์


ได้แล้วครับเปลี่ยน _session เป็น _SESSION มันไม่เหมือนกันครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-04-20 08:32:59 By : mmc01
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : PHP สร้าง session เก็บค่าจาก form ไม่ได้ครับมันไม่แสดงค่า
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่