Deprecated: Function session_register() ขอผู้รู้แนะนำหน่อยครับ
session_register(); เค้าเลิกใช้ไปแล้วครับ
ลองศึกษาดูครับ --> PHP 5 Sessions
Date :
2015-03-19 22:29:33
By :
arm8957
$sess_id='test';
session_register('sess_id');
แก้เป็น
$_SESSION["sess_id"]='test';
Date :
2015-03-20 09:16:21
By :
Chaidhanan
Code (PHP)
<?php
session_start();
$_SESSION["var1"] = $value;
?>
PHP Session ($_SESSION,$HTTP_SESSION_VARS)
Date :
2015-03-20 10:03:08
By :
mr.win
ตอนนี้รันที่เครื่องได้ปกติแต่อัพขึ้นเว็บแล้วไม่ทำงานเรย php ก็เวอร์ชั่นเดียวกัน งงจิงๆ
Date :
2015-03-20 18:24:58
By :
tum015
เอาโค๊ดจริงของ index.php มาแปะดูหน่อยครับ
และเออเร่อร์ ด้วยนะครับ
ส่วนใหญ่ ที่เป็น ปัญหา อัพขึ้นโฮสแล้วไ่ม่ทำงาน
ก็คือ บนโฮส ปิดการทำงานแบบ short tag เอาไว้ครับ
<? เขียนสั้นๆ แค่นี้ไม่ได้ ต้องเขียนเต็ม <?php
2 ก็extension บนเซิฟเวอร์ เปิดไม่ครบตามที่เรา โมฯไว้ เพราะ security หรืออะไรก็ตาม
แต่บน localhost ที่ทดลองทำเปิดมันหมดกี่ตัวลองมันหมดทุกตัว โดยไม่ได้นึกถึง Server
เช่น ตัวแปรแบบ global ซึ่ง admin เขาไล่ปิดกันหมดแล้ว แค่เครื่องเรายังเปิดอยู่
ก็มี 2 ส่วนใหญ่ๆ นี่แหล่ะครับ
Date :
2015-03-20 18:36:38
By :
Chaidhanan
ไม่มี error ครับแต่อัพขึ้น host แร้วไม่ทำงานครับ
--------------------- prd_view ---------------------
Code (PHP)
<?php
session_start();
#include "connect.php";
$id_prd=$_GET["id_prd"];
?>
<input type="hidden" name="id_prd" id="id_prd" value="<?=$id_prd;?>" >
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<head><title></title>
<script type="text/javascript" src="js/jquery.js"></script>
</head>
<body>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/th_TH/sdk.js#xfbml=1&version=v2.0";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<style type="text/css">
*{margin:0px;padding:0;list-style-type:none;}
body{background:#E9F0F5;font-family:Arial, Helvetica, sans-serif;font-size:13px;margin:0px;padding:0px;}
html{background-color:#E9F0F5;}
img{border:none;}
h3{font-family:Tahoma, Geneva, sans-serif;font-size:14px;color:#333;letter-spacing:1px;margin-top:10px;margin-bottom:10px;}
p{margin-bottom:10px;margin-top:10px;line-height:22px;}
.demo{margin:0 auto;width:600px;}
.tickul li{line-height:24px;}
/* zoom-section */
.zoom-section{clear:both;margin-top:20px;}
*html .zoom-section{display:inline;clear:both;}
.zoom-desc{float:left;margin-left:10px;width:310px;margin-bottom:20px;}
.zoom-small-image{border:4px solid #CCC;float:left;margin-bottom:20px;}
.zoom-tiny-image{border:1px solid #CCC;margin:0px;}
.zoom-tiny-image:hover{border:1px solid #C00;}
</style>
<link href="css/cloud-zoom.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/cloud-zoom.1.0.2.min.js"></script>
<table width="100%" border="0" cellspacing="10" >
<?php
$sql="select * from tb_product where id_prd='$id_prd' ";
$result=mysql_query($sql);
$rs=mysql_fetch_array($result);
$id_prd=$rs["id_prd"];
$code=sprintf("%05d",$id_prd);
$name_prd=$rs["name_prd"];
$detail_prd=$rs["detail_prd"];
$ref_id_type=$rs["ref_id_type"];
$price_prd=$rs["price_prd"];
$photo_prd=$rs["photo_prd"];
$vat = ($price_prd*(7/100))+$price_prd;
$stock=$rs["stock"];
if ($stock==0){
$msg="<b>สินค้าหมด";
$link=" <a href='#' ><img src='images/buy.png' border=0 title='ไม่สามารถสั่งซื้อได้สินค้าหมด'></a> ";
}else{
$msg="";
$link= "<a href='index.php?action=basket_add&id_prd=$id_prd' ><input type='button' value='สั่งซื้อ' onClick='addToCart('40');' class='button' /></a>";
}
if ($photo_prd=="") {
$photo_prd="temp.jpg";
}
?>
</table>
<div class="clearfix m_bottom_30 t_xs_align_c">
<div class="p_top_10 t_xs_align_l">
<!--description-->
<div class="demo">
<div class="zoom-section">
<div class="zoom-small-image">
<!--<a href='admin/photo/7486_20150309175529_B.jpg' class = 'cloud-zoom' id='zoom1' rel="adjustX:10, adjustY:-4"><img src="admin/photo/7486_20150309175529.jpg" alt='' title="Optional title display" /></a></div>
<div class="zoom-desc"> -->
<a href='admin/photo/<?=$rs['photo_prd_l']?>' class = 'cloud-zoom' id='zoom1' rel="adjustX:10, adjustY:-4"><img src="admin/photo/<?=$rs['photo_prd_m']?>" alt='' title="Optional title display" /></a></div>
<div class="zoom-desc">
<h3></h3>
<?
# for ($ph = 0; $ph <= 2; $ph++) { ?>
<p><a href='admin/photo/<?=$rs['photo_prd_l']?>' class='cloud-zoom-gallery' title='Red' rel="useZoom: 'zoom1', smallImage: 'admin/photo/<?=$rs['photo_prd_m']?>' "><img class="zoom-tiny-image" src="admin/photo/<?=$rs['photo_prd']?>" alt = "Thumbnail 1"/></a><br>
<? #}?>
<!--<a href='admin/photo/bigimage01.jpg' class='cloud-zoom-gallery' title='Blue' rel="useZoom: 'zoom1', smallImage: ' admin/photo/smallimage-1.jpg'"><img class="zoom-tiny-image" src="admin/photo/tinyimage-1.jpg" alt = "Thumbnail 2"/></a><br>
<a href='admin/photo/bigimage02.jpg' class='cloud-zoom-gallery' title='Blue' rel="useZoom: 'zoom1', smallImage: 'admin/photo/smallimage-2.jpg' "><img class="zoom-tiny-image" src="admin/photo/tinyimage-2.jpg" alt = "Thumbnail 3"/></a></p> -->
</div>
</div><!--zoom-section end--><!--zoom-section end--><!--zoom-section end--></div>
<br>
<table width="100%" >
<tr>
<td> </td>
<td align="right"> </td>
<td colspan="2"><span style="font-size:18px; color:#72b629">
<?=$name_prd ?>
</span></td>
</tr>
<tr>
<td> </td>
<td align="right"> </td>
<td colspan="2"> </td>
</tr>
<tr>
<td> </td>
<td align="right">รหัสสินค้า:</td>
<td colspan="2"><?=$code ?></td>
</tr>
<tr>
<td width="22"> </td>
<td width="77" align="right">ชื่อสินค้า :</td>
<td colspan="2"><a href="#" class="color_dark">
<?=$name_prd ?>
</a></td>
</tr>
<tr>
<td> </td>
<td align="right">คงคลัง :</td>
<td colspan="2"><span class="color_green">มีจำนวน</span>
<?=$stock ?>
ชิ้น</td>
</tr>
<tr>
<td> </td>
<td align="right"> </td>
<td width="68"> </td>
<td width="320"> </td>
</tr>
<tr>
<td> </td>
<td align="right"> </td>
<td><span class="fw_medium m_bottom_10">ราคาสินค้า</span></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td align="right" class="description_table m_bottom_5">ราคาไม่รวมภาษี:</td>
<td class="description_table m_bottom_5"><span class="color_dark">
<?=number_format($price_prd)?>
บาท</span></td>
<td rowspan="2" ><a href="index.php?action=basket_add&id_prd=<?=$id_prd?>"><img src="images/buy-01.png" width="139" height="49"></a></td>
</tr>
<tr>
<td> </td>
<td align="right" class="description_table m_bottom_5">ราคารวมภาษี::</td>
<td class="description_table m_bottom_5"><span class="color_dark">
<?=number_format($vat)?>
บาท</span></td>
</tr>
</table>
<hr class="divider_type_3 m_bottom_10">
<p style="font-size:16px;"><?=$detail_prd?></p>
<hr class="divider_type_3 m_bottom_15">
<div class="d_ib_offset_0 m_bottom_20">
<a href='index.php?action=basket_add&id_prd=<?=$id_prd?>'><input name="add_pro" height="25" type="button" id="add_pro" value="Add to Cart">
</a>
<button class="button_type_12 bg_light_color_2 tr_delay_hover d_inline_b r_corners color_dark m_left_5 p_hr_0"><span class="tooltip tr_all_hover r_corners color_dark f_size_small">Wishlist</span><i class="fa fa-heart-o f_size_big"></i></button>
<button class="button_type_12 bg_light_color_2 tr_delay_hover d_inline_b r_corners color_dark m_left_5 p_hr_0"><span class="tooltip tr_all_hover r_corners color_dark f_size_small">Compare</span><i class="fa fa-files-o f_size_big"></i></button>
<button class="button_type_12 bg_light_color_2 tr_delay_hover d_inline_b r_corners color_dark m_left_5 p_hr_0 relative"><i class="fa fa-question-circle f_size_big"></i><span class="tooltip tr_all_hover r_corners color_dark f_size_small">Ask a Question</span></button>
</div>
<?php
#include "answer_view.php";
?><br>
<div class="fb-comments" data-href="http://<?=$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];?>" data-width="940" data-numposts="10" data-colorscheme="light"></div>
----------------- ส่งมาหน้านี้ครับ basket_add -----------------------------
<?php
session_start();
if ($_SESSION["userid"]==""){
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="javascript">
alert("กรุณาเข้าสู่ระบบก่อนค่ะ!!");
window.location='index.php';
</script>
<?php
exit();
}
$id_prd=$_GET["id_prd"];
/*
@session_register("sess_id");
@session_register("sess_name");
@session_register("sess_price");
@session_register("sess_num");
@session_register("sess_discount");
@session_register("sess_pricephone");
*/
$_SESSION["sess_id"] = $sess_id ;
$_SESSION["sess_name"] = $sess_name;
$_SESSION["sess_price"] = $sess_price;
$_SESSION["sess_num"] = $sess_num;
$_SESSION["sess_discount"] = $sess_discount;
$_SESSION["sess_pricephone"] = $sess_pricephone;
if (count($sess_id)=="0") {
$check=1;
} else if (!in_array($id_prd, $sess_id)) {
$check=1;
}
if ($check==1) {
include "connect.php";
$sql_p="select * from tb_product where id_prd='$id_prd' ";
$result_p=mysql_query($sql_p);
$rs=mysql_fetch_array($result_p);
$price = $rs["price_prd"];
//$vat = ($price*(7/100))+$price;
$sess_id[]=$rs["id_prd"];
$sess_name[]=$rs["name_prd"];
$sess_price[]=$price;
$sess_num[]=1;
$sess_discount[]=0;
$sess_pricephone[]=$price;
}
echo "SS::".$sess_id;
print_r($_SESSION);
#header("Location: index.php?action=basket");
echo "<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
</head>
<body>
<meta http-equiv='refresh' content='0; Url=index.php?action=basket'>
</body>
</html>";
?>
<?php session_start(); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
</head>
<body onLoad="document.main.username.focus()">
</body>
</html>
-------------------- แร้วค่อยมาแสดงหน้านี้ครับ basket -------------------------------
Code (PHP)
<?php
session_start();
#$amphur=$_GET["amphur"];
#print_r($_REQUEST);
if ($_SESSION["userid"]==""){
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="javascript">
alert("คุณต้องเข้าสู่ระบบก่อนค่ะ!!");
window.location='index.php';
</script>
<?php
exit();
}
echo "SS::".$sess_id;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Basket</title>
<script type="text/javascript">
function doCalculate() {
document.form1.action ="basket_cal.php?CheckItem=0";
document.form1.submit();
}
function doOrder() {
document.form1.action ="prd_order.php";
document.form1.submit();
}
function doOrderAdd() {
document.form1.action ="index.php?action=list_product";
document.form1.submit();
}
</script>
</head>
<body>
<?php
if (count($sess_id)==0) {
echo "<font face=\"Tahoma\" size=\"2\" color='#FF0000'>ยังไม่มีสินค้าอยู่ในตะกร้าค่ะ </font>";
} else {
?>
<form method="post" name="form1" >
<hr class="m_bottom_30 divider_type_3">
<table class="table_type_1 responsive_table full_width t_align_l r_corners wraper shadow bg_light_color_1 m_bottom_30">
<thead>
<tr class="f_size_large">
<!--titles for td-->
<th>Product Code</th>
<th>Product Name</th>
<th>Price(Baht)</th>
<th>Discount</th>
<th>Amount</th>
<th>Quanity</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
for ($i=0;$i<count($sess_id);$i++) {
$total_unit=$sess_num[$i]*$sess_price[$i];
$total=$total+$total_unit;
$vat2=floor($total*(7/100));
$total2=$total+$vat2;
?>
<tr>
<!--product image-->
<td data-title="Product Image"> <?=$sess_id[$i]?> </td>
<!--product name and category-->
<td data-title="Product Name">
<a href="#" class="fw_medium d_inline_b f_size_ex_large color_dark m_bottom_5"><?=$sess_name[$i]?></a>
</td>
<!--product price-->
<td data-title="Price">
<span class="scheme_color fw_medium f_size_large"><?=number_format($sess_pricephone[$i])?></span>
</td>
<!--product discount-->
<td data-title="Price">
<span class="scheme_color fw_medium f_size_large"><?=$sess_discount[$i]?>%</span>
</td>
<!--product amount-->
<td data-title="Price">
<span class="scheme_color fw_medium f_size_large"><?=number_format($total_unit)?></span>
</td>
<!--quanity-->
<td data-title="Quantity">
<div class="clearfix quantity r_corners d_inline_middle f_size_medium color_dark">
<input type="number" name="prd_num[]" value="<?=$sess_num[$i]?>" class="f_left">
</div>
</td>
<!--add or remove buttons-->
<td data-title="Action">
<a href="basket_cal.php?prd_del[]=<?=$sess_id[$i]?>&CheckItem=1" class="color_dark" ><i class="fa fa-times m_right_5"></i> Remove</a>
</td>
</tr>
<?php }
?>
<tr>
<td colspan="6">
<p class="fw_medium f_size_large t_align_r t_xs_align_c">รวมเป็นเงิน: </p>
</td>
<td colspan="1">
<p class="fw_medium f_size_large color_dark"><?=number_format($total)?></p>
</td>
</tr>
<td colspan="6">
<p class="fw_medium f_size_large t_align_r t_xs_align_c">ภาษีมูลค่าเพิ่ม (7%):</p>
</td>
<td colspan="1">
<p class="fw_medium f_size_large color_dark"><?=number_format($vat2)?></p>
</td>
</tr>
<td colspan="6">
<p class="fw_medium f_size_large t_align_r t_xs_align_c">ยอดเงินที่ต้องชำระ:</p>
</td>
<td colspan="1">
<p class="fw_medium f_size_large color_dark"><?=number_format($total2)?></p>
</td>
</tr>
<td colspan="7"> <div align="right">
<button class="tr_delay_hover r_corners button_type_15 bg_dark_color bg_cs_hover color_light" onClick="doOrderAdd();">สั่งสินค้าเพิ่ม</button>
<button class="tr_delay_hover r_corners button_type_15 bg_dark_color bg_cs_hover color_light" onClick="doCalculate();">คำนวณใหม่</button>
<button class="tr_delay_hover r_corners button_type_15 bg_dark_color bg_cs_hover color_light" onClick="doOrder();">สั่งซื้อสินค้า</button>
</div>
</td>
</tr>
</p>
</form>
<?php
}
?>
</tbody>
</table>
</body>
</html>
ประวัติการแก้ไข 2015-03-20 21:31:06 2015-03-20 21:34:01
Date :
2015-03-20 21:27:21
By :
tum015
ไม่ครับ No. 9
Date :
2015-03-20 22:18:54
By :
tum015
ตอนนี้ส่งค่าได้แร้วครับ เป็นเพราะ ตัวแปรแบบ global ที่ No. 9 (Chaidhanan) แต่ตอนนี้ array ไม่ทำงานครับ ก็ตามแก้ต่อไป
Date :
2015-03-20 22:23:23
By :
tum015
ตอนนี้บนเครื่องปกติ แต่อัพขึ้น host แล้ว array ไม่ทำงานเก็บแค่ค่าเดียว
Date :
2015-03-20 23:57:57
By :
tum015
ขอบคุณครับ คุณChaidhanan
เหลือส่วนนี้ที่ไม่ทำงานครับ ส่วนค่าไปคำนวณสินค้าและลบ สินค้าไม่ได้ รันที่เครื่องปกติแต่ host ไม่ทำงาน
############ basket #################
Code (PHP)
<script type="text/javascript">
function doCalculate() {
document.form1.action ="basket_cal.php?checkitem=0";
document.form1.submit();
}
function doOrder() {
document.form1.action ="prd_order.php";
document.form1.submit();
}
function doOrderAdd() {
document.form1.action ="index.php?action=list_product";
document.form1.submit();
}
</script>
</head>
<body>
<?php
if (count($sess_id)==0) {
echo "<font face=\"Tahoma\" size=\"2\" color='#FF0000'>ยังไม่มีสินค้าอยู่ในตะกร้าค่ะ </font>";
} else {
?>
<form method="post" name="form1" >
<hr class="m_bottom_30 divider_type_3">
<table class="table_type_1 responsive_table full_width t_align_l r_corners wraper shadow bg_light_color_1 m_bottom_30">
<thead>
<tr class="f_size_large">
<!--titles for td-->
<th>Product Code</th>
<th>Product Name</th>
<th>Price(Baht)</th>
<th>Discount</th>
<th>Amount</th>
<th>Quanity</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
for ($i=0;$i<count($sess_id);$i++) {
$total_unit=$sess_num[$i]*$sess_price[$i];
$total=$total+$total_unit;
$vat2=floor($total*(7/100));
$total2=$total+$vat2;
?>
<tr>
<!--product image-->
<td data-title="Product Image"> <?=$sess_id[$i]?> </td>
<!--product name and category-->
<td data-title="Product Name">
<a href="#" class="fw_medium d_inline_b f_size_ex_large color_dark m_bottom_5"><?=$sess_name[$i]?></a>
</td>
<!--product price-->
<td data-title="Price">
<span class="scheme_color fw_medium f_size_large"><?=number_format($sess_pricephone[$i])?></span>
</td>
<!--product discount-->
<td data-title="Price">
<span class="scheme_color fw_medium f_size_large"><?=$sess_discount[$i]?>%</span>
</td>
<!--product amount-->
<td data-title="Price">
<span class="scheme_color fw_medium f_size_large"><?=number_format($total_unit)?></span>
</td>
<!--quanity-->
<td data-title="Quantity">
<div class="clearfix quantity r_corners d_inline_middle f_size_medium color_dark">
<input type="number" name="prd_num[]" value="<?=$sess_num[$i]?>" class="f_left">
</div>
</td>
<!--add or remove buttons-- basket_cal.php?prd_del[]=<?#$sess_id[$i]?>&CheckItem=1 -->
<td data-title="Action">
<a href="basket_cal.php?prd_del[]=<?=$sess_id[$i]?>&checkitem=1" class="color_dark" ><i class="fa fa-times m_right_5"></i> Remove</a>
</td>
</tr>
<?php }
?>
<tr>
<td colspan="6">
<p class="fw_medium f_size_large t_align_r t_xs_align_c">รวมเป็นเงิน: </p>
</td>
<td colspan="1">
<p class="fw_medium f_size_large color_dark"><?=number_format($total)?></p>
</td>
</tr>
<td colspan="6">
<p class="fw_medium f_size_large t_align_r t_xs_align_c">ภาษีมูลค่าเพิ่ม (7%):</p>
</td>
<td colspan="1">
<p class="fw_medium f_size_large color_dark"><?=number_format($vat2)?></p>
</td>
</tr>
<td colspan="6">
<p class="fw_medium f_size_large t_align_r t_xs_align_c">ยอดเงินที่ต้องชำระ:</p>
</td>
<td colspan="1">
<p class="fw_medium f_size_large color_dark"><?=number_format($total2)?></p>
</td>
</tr>
<td colspan="7"> <div align="right">
<button class="tr_delay_hover r_corners button_type_15 bg_dark_color bg_cs_hover color_light" onClick="doOrderAdd();">สั่งสินค้าเพิ่ม</button>
<button class="tr_delay_hover r_corners button_type_15 bg_dark_color bg_cs_hover color_light" onClick="doCalculate();">คำนวณใหม่</button>
<button class="tr_delay_hover r_corners button_type_15 bg_dark_color bg_cs_hover color_light" onClick="doOrder();">สั่งซื้อสินค้า</button>
</div>
</td>
</tr>
</p>
<?php
}
?>
</tbody>
</table>
</form>
############# ส่งมาหน้านี้ครับ ##############
Code (PHP)
$checkitem=$_REQUEST["checkitem"];
if (count($prd_del)==0) {
$prd_del=array();
}
if ($checkitem==1 ) {
for ($i=0;$i<count($sess_id);$i++) {
if (!in_array($sess_id[$i],$prd_del)) {
$temp_id[]=$sess_id[$i];
$temp_name[]=$sess_name[$i];
$temp_price[]=$sess_price[$i];
$temp_num[]=$sess_num[$i];
$temp_pricephone[]=$sess_pricephone[$i];
$temp_discount[]=$sess_discount[$i];
}
}
}
#Menu remove
elseif($checkitem==0){
for ($i=0;$i<count($sess_id);$i++) {
if (!in_array($sess_id[$i],$prd_del)) {
$temp_id[]=$sess_id[$i];
$temp_name[]=$sess_name[$i];
$temp_price[]=$sess_price[$i];
$temp_num[]=$prd_num[$i];
$temp_pricephone[]=$sess_pricephone[$i];
$temp_discount[]=$sess_discount[$i];
}
}
}
$sess_id=$temp_id;
$sess_name=$temp_name;
$sess_price=$temp_price;
$sess_num=$temp_num;
$sess_pricephone=$temp_pricephone;
$sess_discount=$temp_discount;
Date :
2015-03-21 11:40:24
By :
tum015
ต้องกำหนดตัวแปร global ใหม่ครับ โค๊ดข้างล่าง นี้เป็นจุดเริ่มต้นตรวจสอบ
if (count($sess_id)==0) {
แก้เป็น
if (count($_SESSION['sess_id'])==0) {
//ตรวจสอบเสร็จแล้ว ใช้คำสั่งแปลง
extract($_SESSION ); // คำสั่งนี้จะแปลง array ออกมาอยู่ในรูปตัวตัวแปรเรียกใช้ได้งานเลย
ลองเปิด document extract ดูนะครับ
http://php.net/manual/en/function.extract.php
Date :
2015-03-21 11:52:38
By :
Chaidhanan
ช่วยดูให้หน่อยได้ไหมครับ ผมก็แก้จาก ส่งค่าไม่ได้คับ งง
Code (PHP)
<?php
session_start();
$id = $_GET['id'];
$_SESSION["sess_id"] = $sess_id ;
$_SESSION["sess_name"] = $sess_name;
$_SESSION["sess_price"] = $sess_price;
$_SESSION["sess_num"] = $sess_num;
if (count($_SESSION['sess_id']) == 0) {
$check = 1;
} else if (!in_array($id, $sess_id)) {
$check = 1;
}
if ($check == 1) {
include "connectdb.php";
$sql = "select * from product where product_id = '$id'";
$ex = mysql_query($sql, $conn);
$rs = mysql_fetch_array($ex);
$sess_id[] = $rs[product_id] ;
$sess_name[] = $rs[product_name] ;
$sess_price[] = $rs[product_price] ;
$sess_num[] = 1;
}
echo "<meta http-equiv='refresh' content='0; url=basket.php'>";
?>
Date :
2016-05-16 13:06:32
By :
noom
Load balance : Server 03