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 > ช่วยหน่อยครับ Error แบบนี้ จะทำการตัดสต้อกของ You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Product='1'' at line 1



 

ช่วยหน่อยครับ Error แบบนี้ จะทำการตัดสต้อกของ You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Product='1'' at line 1

 



Topic : 127417



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



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




ช่วยหน่อยครับ Error จะทำการตัดสต้อกของ
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Product='1'' at line 1

Code (PHP)
<?session_start();?>
<?//ส่วนของ SESSION

$_SESSION['name'];
$U_name = $_SESSION['name'];

$_SESSION['user'];
$Euser = $_SESSION['user'];

?>
<?//Connect DATABASE

//ส่วนการทำให้เกิดการเชื่อมฐานข้อมูล
		$hostname = "localhost";
		$username = "root";
		$pass = "1234"; // ตามที่เราตั้งค่าไว้
		$dbname = "itshoes"; //ชื่อฐานข้อมูล

		$connect = mysql_connect($hostname,$username,$pass); //ฟังก์ชัน mysql_connect เป็นฟังก์ชนเริ่มเชื่อมต่อระบบฐานข้อมูล MySQL
		$sql = mysql_select_db($dbname); //ฟังก์ชัน mysql_select_db คือการเลือกใช้ฐานข้อมูล
		if(!$connect) die ("ไม่สารมารถเข้าสู่ระบบได้"); //ฟังก์ชัน mysql_connect มักจะใช้ควบคู่กับตัวดำเนินการ or เพื่อให้แสดงผลในกรณีที่ไม่สามารถเชื่อมต่อกับโฮสต์
		if(!$sql) die ("ไม่สามารถเชื่อมต่อได้");
		mysql_query("SET NAMES UTF8");

		$select = "select * from product where ProductID='$id' ";// select ข้อมูลท่เราจะใช้ qurey
		$result = mysql_query($select);//การติดต่อกับฐานข้อมูลแล้ว query ข้อมูล จาก ตัวแปล $select
		$query = mysql_query($select,$connect); //การติดต่อกับฐานข้อมูลแล้ว query ข้อมูล จาก ตัวแปล $select และ ตัวแปล $connect
		while($show = mysql_fetch_array($query)){

		$_SESSION['ProductID'] = $show['ProductID']; //เอาตัวแปร SESSion มาเก็บค่าไว้
		$_SESSION['ProductName'] = $show['ProductName'];
		$_SESSION['ProductBand'] = $show['ProductBand'];
		$_SESSION['Detail'] = $show['Detail'];
		$_SESSION['Price'] = $show['Price'];
		$_SESSION['Total'] = $show['Total'];
		$_SESSION['Picture'] = $show['Picture'];

	}
	$IDProduct=$_SESSION['ProductID'] ;
	$NameProduct=$_SESSION['ProductName'] ;
	$BandProduct=$_SESSION['ProductBand'] ;
	$DetailProduct=$_SESSION['Detail'] ;
  $PriceProduct=$_SESSION['Price'] ;
	$TotalProduct=$_SESSION['Total'] ;
	$PictureProduct=$_SESSION['Picture'];


		$select1 = "select  U_name,U_lastname,U_home,U_phone,U_email  from user where U_email='$Euser'";// select ข้อมูลท่เราจะใช้ qurey
		$result1 = mysql_query($select1);//การติดต่อกับฐานข้อมูลแล้ว query ข้อมูล จาก ตัวแปล $select
		$query1 = mysql_query($select1,$connect); //การติดต่อกับฐานข้อมูลแล้ว query ข้อมูล จาก ตัวแปล $select และ ตัวแปล $connect
		while($show = mysql_fetch_array($query1)){

	 		$U_name = $show['U_name'];
	 		$U_lastname = $show['U_lastname'];
			$U_home = $show['U_home'];
			$U_phone = $show['U_phone'];
	 		$U_email = $show['U_email'];


	 	}

?>
<!doctype html>

<head>
    <title>ตารางสินค้า</title>
		<meta http-equiv=Content-Type content="text/html; charset=utf-8">
		<link rel="stylesheet" type="text/css" href="mystyle.css">
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
		<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <body background="5.jpg">

        <style>
            A:link {
                color: #F7B810;
                text-decoration: none
            }

            A:visited {
                color: #F7B810;
                text-decoration: none
            }

            A:hover {
                color: #F7B810
            }

            ul {
                list-style-type: none;
                margin: 0;
                padding: 0;
                overflow: hidden;
                background-color: #333;
            }

            li {
                float: left;
            }

            li a {
                display: block;
                color: white;
                text-align: center;
                padding: 14px 16px;
                text-decoration: none;
            }

            li a:hover:not(.active) {
                background-color: #111;
            }

            .active {
                background-color: #4CAF50;
            }

            table,
            th,
            td {
                border: 1px solid black;
                border-collapse: collapse;
            }

            th,
            td {
                padding: 20px;
            }

            p.big {
                font-size: 45pt;
                text-align: center;
                color: white;
            }

            .container {
                position: relative;
                width: 50%;
				clear: right;
				float: left;

            }

            .image {
                display: block;
                width: 100%;
                height: auto;
            }

            .overlay {
                position: absolute;
                bottom: 0;
                left: 0;
                right: 0;
                background-color: #008CBA;
                overflow: hidden;
                width: 100%;
                height: 0;
                transition: .5s ease;
            }

            .container:hover .overlay {
                height: 100%;
            }

            .text {
                white-space: nowrap;
                color: white;
                font-size: 20px;
                position: absolute;
                overflow: hidden;
                top: 50%;
                left: 50%;
                transform: translate(-50%, -50%);
                -ms-transform: translate(-50%, -50%);
            }
        </style>
          <ul>
						<ul>
							 <li><img src="1.png" width="100" height="50" />
								 &nbsp&nbsp
								 <li><a href=Home.php> Home</a></li>
								 <li><a href=product.php> Product</a></li>
								 <li><a href=edituser.php>Edit Profile</a></li>
								<li><a href=buy.php>buy product </a></li>
								 <li><a href=Logout.php>log out</a></li>
								 <li><a href="">สวัสดีUser : <?echo $U_name?></a></li>
					 </ul>
					 <body background="6.jpg">
        </ul>
</head>

<body>
<center>
<table width="400"  border="1">
 <tr>
	 <td width="101">ProductID</td>
	 <td width="82">ProductName</td>
	 <td width="82">Price</td>
	 <td width="79">Qty</td>
	 <td width="79">Total</td>
	 <td width="10">Del</td>
 </tr>
 <?php
 $Total = 0;//เก็บค่าสินค้าที่ซื้อ
 $SumTotal = 0;//เก็บค่ารวมทั้งหมดที่ซื้อ
?>
<h2> รายการที่คุณเลือกซื้อ <h2>
	<form action='buy.php' method='post'>
<?php
 for($i=0;$i<=(int)$_SESSION["intLine"];$i++)//สร้างตาราง
 {
	 if($_SESSION["strProductID"][$i] != "")//strProductID ถ้าไม่ว่าง
	 {
	$select = "select * from product where ProductID='".$_SESSION["strProductID"][$i]."'";// select ข้อมูลท่เราจะใช้ qurey
	 $result = mysql_query($select);//การติดต่อกับฐานข้อมูลแล้ว query ข้อมูล จาก ตัวแปล $select
	 $query = mysql_query($select,$connect); //การติดต่อกับฐานข้อมูลแล้ว query ข้อมูล จาก ตัวแปล $select และ ตัวแปล $connect
	 $show= mysql_fetch_array($query);//ใช้ในการคืนค่าข้อมูลในฐานข้อมูลที่อยู่ในลักษณะเป็นแถวหรือว่าเป็น record
	 $Total = $_SESSION["strQty"][$i] * $show["Price"];
	 $SumTotal = $SumTotal + $Total;
	 ?>
	 <tr>
	 <td><?php echo $_SESSION["strProductID"][$i];?>
		<input type="hidden" name="txtProductID<?php echo $i;?>" value="<?php echo $_SESSION["strProductID"][$i];?>"></td>
	 <td><?php echo $show["ProductName"];?></td>
	 <td><?php echo  number_format ($show["Price"]);?></td>
	 <td><input type="text" name="Qty<?php echo $i;?>" value="<?php echo $_SESSION["strQty"][$i];?>" size="2"></td><!--จำนวนสินค้าที่สั่งซื้อ
	 -->
	 <td><?php echo number_format($Total,2);?></td>
	 <td><a href="delete.php?Line=<?php echo $i;?>">x</a></td>
</tr>
	 </tr>



	 <?php
	 }
 }
 ?>
 </table>
 <h2> จำนวนเงินที่ต้องชำระ <?php echo number_format ($SumTotal,2); ?> <h2><br>
 					 <input id="submit" type="submit" name="submit" value="ยืนยันการสั่งซื้อ" class="btn btn-primary" >
				 </form>
 <br>
 <?php
 	if($_POST['submit']!=null){

 		$hostname = "localhost";
 		$username = "root";
 		$password = "1234";
 		$dbname = "itshoes";

 		$connect = mysql_connect($hostname,$username,$password);
 			if(! $connect) die ("ไม่สามารถเชื่อต่อได้");

 				mysql_select_db($dbname,$connect) or die ("ไม่สามารถเลือกฐานข้อมูลได้");
 				mysql_query("SET NAMES UTF8");


 		$insert = "INSERT INTO orders (Name,Lastname,Address,Tel,U_email,staut)
 								VALUES ('$U_name','$U_lastname','$U_home','$U_phone','$U_email','ยังไม่ได้ชำระ')";

 		mysql_query($insert,$connect) or  die(mysql_error());
		$strOrderID = mysql_insert_id();

  for($i=0;$i<=(int)$_SESSION["intLine"];$i++)
  {
	  if($_SESSION["strProductID"][$i] != "")
	  {
			  $strSQL = "
				INSERT INTO orders_detail (OrderID,ProductID,Qty)
				VALUES
				('".$strOrderID."','".$_SESSION["strProductID"][$i]."','".$_SESSION["strQty"][$i]."')
			  ";
	   $update ="update product SET Total = Total-".$_SESSION["strQty"][$i]."where ProductID='".$_SESSION["strProductID"][$i]."'";
          mysql_query($update,$connect) or  die(mysql_error());
			  mysql_query($strSQL) or die(mysql_error());



	  }
  }
		echo "<script type='text/javascript'>confirm('ทำการซื้อแล้ว สามารถตรวจสอบได้ที่หน้า BASKET');</script>";
 		//echo "<script type='text/javascript'>confirm('บันทึกข้อมูลแล้ว');</script>";
	}
?>





</body>
</html>




Tag : PHP, MySQL









ประวัติการแก้ไข
2017-04-30 09:50:37
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2017-04-30 00:11:13 By : zoneteendome View : 597 Reply : 2
 

 

No. 1



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



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


ตรง $update ที่เป็นปัญหาอะครับ ช่วยหน่อยครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-04-30 00:12:01 By : zoneteendome
 


 

No. 2



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

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

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

Code
echo $update; mysql_query($update,$connect) or die(mysql_error());


ลอง echo ค่าออกมาดูครับ ก็จะรู้ว่าเป็นอะไรครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-05-01 09:54:19 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยหน่อยครับ Error แบบนี้ จะทำการตัดสต้อกของ You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Product='1'' at line 1
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 01
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 อัตราราคา คลิกที่นี่