|
|
|
ช่วยดูโค๊ดให้หน่อยค่ะ วนลูปแล้วข้อมูลตัวแรกไม่เข้าในฐานข้อมูล แต่ข้อมูลตัวถัดไปจะเข้าไปยังฐานข้อมูลค่ะ |
|
|
|
|
|
|
|
คือเมื่อใส่ข้อมูลแล้วจะแสดงออเดอร์ เมื่อกดส่งออเดอร์ ข้อมูลแรกไม่ลงในฐานข้อมูล แต่เป็นข้อมูลตัวถัดจากนั้นค่ะ
makeup.php
<?
session_start();
$host="localhost";
$user="root";
$pass="root";
$database="skinfood";
//$con=mysql_connect($host,$user,$pass);
$mysqli = new mysqli($host, $user, $pass, $database);// database connection for mysql5
if ($mysqli->connect_error) {
die('Connect Error (' . $mysqli->connect_errno . ') ' // if cannot connect . stop and echo error
. $mysqli->connect_error);
}
$mysqli->query('SET NAMES UTF8');// set character to utf-8
if ($_GET['menu']=="add_order")
{
if ($_GET['item_id'])
{
if ($_SESSION['loop']=='')
{
$_SESSION['loop']=1;//exit();
}else
{
$sloop = (int)$_SESSION['loop'];
$sloop = $sloop+1;
$_SESSION['loop'] = $sloop;
}
$_SESSION['type'.$sloop] ="makeup";
$_SESSION['item_id'.$sloop] = $_GET['item_id'];
$_SESSION['amount'.$sloop] = $_GET['amount'];
echo "<script>window.location='makeup.php';</script>";
}else
{
echo "<script>alert('ข้อมูลไม่เพียงพอ');history.go(-1);</script>";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script>
var intRegex = /^\d+$/;
</script>
<style type="text/css">
body {
background-color: #FFFFFF;
background-image: url();
background-repeat: no-repeat;
}
</style>
</head>
<body>
<p> </p>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<p> </p>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<p><img src="04.jpg" width="302" height="300" /></p>
<blockquote>
<p><!--img src="../image/B01.jpg" width="207" height="206" /><img src="../image/BB.jpg" width="75" height="204" /><img src="../image/B02.jpg" width="210" height="206" /><img src="../image/BB.jpg" alt="" width="75" height="204" /><img src="../image/B03.jpg" width="215" height="208" /><img src="../image/BB.jpg" alt="" width="75" height="204" /><img src="../image/B04.jpg" width="180" height="211" /></p>
<p> </p>
<p><img src="../image/Black Forest.jpg" width="181" height="103" /><img src="../image/BB.jpg" alt="" width="115" height="127" /><img src="../image/Banoffee Crumble.jpg" width="178" height="109" /><img src="../image/BB.jpg" alt="" width="125" height="126" /><img src="../image/Tiramisu.jpg" width="166" height="105" /><img src="../image/BB.jpg" alt="" width="95" height="126" /><img src="../image/Vanilla Panna.jpg" width="168" height="102" /-->
<?
$sql = "select * from makeup";
$result = $mysqli->query($sql);
if ($result->num_rows>0)
{
while ($db=$result->fetch_array(MYSQLI_NUM))
{
if ($_SESSION['username'] && $_SESSION['id'] && $_SESSION['name'] && $_SESSION['tel'] && $_SESSION['email'] && $_SESSION['address'] && $_SESSION['status'])
{
$js = "style=\"cursor:pointer\" onclick=\"amount=prompt('ราคาชิ้นละ ".$db[3]." บาท ท่านต้องการรับกี่ชิ้นค่ะ');if(intRegex.test(amount)) {pass=1;}else{alert('กรุณาใส่จำนวนเต็มเท่านั้น');}if (amount==0){pass=0;alert('กรุณาใส่จำนวนมากกว่า 0');}if (amount && pass){pass=0;window.location='makeup.php?menu=add_order&item_id=".$db[0]."&amount='+amount;}\"";
}
?>
</p>
<table width="200" border="1">
<tr>
<th scope="col"><p><img src="VITA TOK LIPGLOSS OR02 2.jpg" <?=$js?>width="400" height="400" border="0" /></p>
<pre>VITA TOK LIPGLOSS OR02</pre></th>
<th scope="col"><p><img src="SWEET ALMOND EYELINER1.jpg" width="400" height="400" /></p>
<pre>SWEET ALMOND EYELINER</pre></th>
<th scope="col"><p><img src="EGGPLANT PLUMPING VOLUME MASCARA_1.jpg" width="397" height="399" /></p>
<pre>EGGPLANT PLUMPING VOLUME MASCARA</pre></th>
</tr>
<tr>
<td><img src="TOMATO COOL JELLY TINT1_1.jpg" width="400" height="400" /></td>
<td><img src="EGGPLANT PEN EYELINER1_2.jpg" width="409" height="383" /></td>
<td><img src="CHOCO SMOKY VOLUME MASCARA 2(CHOCO BROWN)1.jpg" width="400" height="400" /></td>
</tr>
</table>
<p>
</p>
</blockquote>
<?
$x .= "<img src=\"../".$db[1]."\" ".$js." width=\"210\" height=\"206\" /><img src=\"../image/BB.jpg\" width=\"75\" height=\"204\" />";
}
}
?>
<?="</p><p>".$x?>
</p>
<?
//echo $_SESSION['loop'];exit();
$sloop = $_SESSION['loop'];
if ($sloop>=1)
{
//echo $_SESSION['loop'];exit();
//$loop = $x = 1;
?>
<fieldset>
<legend>รายการสั่งไปแล้ว</legend>
<table border="1" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center">ลำดับ</td>
<td align="center">ชนิด</td>
<td align="center">จำนวน</td>
</tr>
<?
//$sloop = $_SESSION['loop'];
//echo $_SESSION['loop'];exit();
//$loop1 = 1;//echo $sloop;
$x = 1;
while ($loop1<=(int)$sloop)
{
$sql = "select * from ".$_SESSION['type'.$loop1]." where item_id='".$_SESSION['item_id'.$loop1]."'";//echo $sql;
$result = $mysqli->query($sql);//echo $sql;
if ($result->num_rows>0)
{
while ($db=$result->fetch_array(MYSQLI_NUM))
{
?>
<tr>
<td align="center"><?=$x?></td>
<td align="center"><?=$_SESSION['type'.$loop1]?></td>
<td align="center"><?=$_SESSION['amount'.$loop1]?></td>
</tr>
<?
$sum += $db[3]*$_SESSION['amount'.$loop1];
$x++;
}
}//echo $loop."<br />";
$loop1 += 1;
}
?>
<tr>
<td colspan="4">รวมเป็นเงินทั้งหมด <?=$sum?> บาท <a href="submit_order.php">ส่งออเดอร์ให้ร้าน</a></td>
</tr>
</table>
</fieldset>
<?
}
?>
</body>
</html>
โค๊ดนี้คือตัวรับค่าที่ส่งจาก makeup.php
submit_order.php
<?
session_start();
$host="localhost";
$user="root";
$pass="root";
$database="skinfood";
//$con=mysql_connect($host,$user,$pass);
$mysqli = new mysqli($host, $user, $pass, $database);// database connection for mysql5
if ($mysqli->connect_error) {
die('Connect Error (' . $mysqli->connect_errno . ') ' // if cannot connect . stop and echo error
. $mysqli->connect_error);
}
$mysqli->query('SET NAMES UTF8');// set character to utf-8
$sloop = $_SESSION['loop'];
if ($sloop)
{
$loop = $x = 1;
while ($loop<=$sloop)
{
$sql = "insert into item_order values(0,'".$_SESSION['id']."','".$_SESSION['type'.$loop]."','".$_SESSION['item_id'.$loop]."',".$_SESSION['amount'.$loop].",NOW())";//echo $sql;exit();
$result = $mysqli->query($sql);
$_SESSION['type'.$loop] = "";
$_SESSION['item_id'.$loop] = "";
$_SESSION['amount'.$loop] = "";
$loop++;
}
$_SESSION['loop'] = '';
echo "$sql";
//echo "<script>alert('ส่งออเดอร์ให้ทางร้านรับทราบแล้วค่ะ ขอบคุณที่ใช้บริการค่ะ');window.location='index.php';</script>";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>
ไม่ทราบว่าผิดพลาดตรงไหน ช่วยด้วยนะคะ
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2013-05-31 14:59:51 |
By :
iiampare |
View :
827 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$loop = $x = 1;
มาจากไหนครับ
ลองเปลี่ยนเป็น $loop=1;
|
|
|
|
|
Date :
2013-05-31 15:53:43 |
By :
pklangkua |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณมากค่ะ เดี๋ยวจะลองเปลี่ยนดู แล้วจะมาบอกนะคะ
|
|
|
|
|
Date :
2013-06-16 17:18:04 |
By :
iiampare |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไม่ได้อ่ะค่ะ มันก็ยังเหมือนเดิม แล้วก็ไม่มี error อะไรเลยค่ะ
|
|
|
|
|
Date :
2013-06-16 17:38:06 |
By :
iiampare |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while ($loop<=$sloop) ===> while ($sloop >= 1 )
ลองดู
|
|
|
|
|
Date :
2013-06-20 16:58:27 |
By :
SN |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|