ขอความช่วยเหลือครับ You have an error in your SQL syntax
อยากรบกวนพี่ๆเพื่อนๆช่วยไล่โค้ดให้นิดนึงครับว่าผิดตรงไหน ผมลองแก้มา 1 วันแล้ว ยังไม่ได้เลยครับ
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 '' at line 1
ขอบคุณครับ
Code (PHP)
<? error_reporting(0);
session_start();
include ('admin/module/connect.php');
include ('admin/module/function.php');?>
<script type="text/javascript">
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
</script>
<?
$Act=$_GET['Act'];
switch($Act){
case 'Category' : $Act=$_GET['Act'];
$CatId=$_GET['CatId'];
$Search=$_GET['Search'];
$SelectCat=Select("db_category","WHERE CatId='".$CatId."'");
$Cat=mysql_fetch_array($SelectCat);
$Title="PRODUCT : ".$Cat['CatName'];
$Table="db_product";
$Condition="WHERE CatId='".$CatId."'AND Quanlity > 0 AND ProductName LIKE '%".$Search."%'";
$Hidden="<input type=\"hidden\" name=\"Act\" value=\"$Act\"><input type=\"hidden\" name=\"CatId\" value=\"$CatId\">";
$PageDetail="&Act=".$Act."&CatId=".$CatId."&Search=".$Search;
break;
case 'Product' : $Act=$_GET['Act'];
$Search=$_GET['Search'];
$Title="TOTAL PRODUCT";
$Table="db_product";
$Condition="WHERE ProductName LIKE '%".$Search."%'AND Quanlity > 0";
$Hidden="<input type=\"hidden\" name=\"Act\" value=\"$Act\">";
$PageDetail="&Act=".$Act."&Search=".$Search;
break;
case 'New' : $Act=$_GET['Act'];
$New=$_GET['New'];
$Search=$_GET['Search'];
$Title="NEW PRODUCTS";
$Table="db_product";
$Condition="WHERE New='".$New."'AND Quanlity > 0 AND ProductName LIKE '%".$Search."%'";
$Hidden="<input type=\"hidden\" name=\"Act\" value=\"$Act\"><input type=\"hidden\" name=\"New\" value=\"$New\">";
$PageDetail="&Act=".$Act."&New=".$New."&Search=".$Search;
break;
case 'Promotion': $Act=$_GET['Act'];
$Promotion=$_GET['Promotion'];
$Search=$_GET['Search'];
$Title="PROMOTION PRODUCT";
$Table="db_product";
$Condition="WHERE Promotion='".$Promotion."'AND Quanlity > 0 AND ProductName LIKE '%".$Search."%'";
$Hidden="<input type=\"hidden\" name=\"Act\" value=\"$Act\"><input type=\"hidden\" name=\"Promotion\" value=\"$Promotion\">";
$PageDetail="&Act=".$Act."&Promotion=".$Promotion."&Search=".$Search;
break;
case 'ProductSearch' : $Act=$_GET['Act'];
$CatId=$_GET['CatId'];
$New=$_GET['New'];
$Promotion=$_GET['Promotion'];
$ProductName=$_GET['ProductName'];
$Title="Search Products";
if($CatId != ''){
$CatIdSearch="CatId='".$CatId."'";
}else{
$CatIdSearch="CatId LIKE '%".$CatId."%'";
}
if($New != ""){
$NewSearch="New='".$New."'";
}else{
$NewSearch="New LIKE '%".$New."%'";
}
if($Promotion != ""){
$PromotionSearch="Promotion='".$Promotion."'";
}else{
$PromotionSearch="Promotion LIKE '%".$Promotion."%'";
}
$Table="db_product";
$Condition="WHERE $CatIdSearch AND Quanlity > 0 AND $NewSearch AND $PromotionSearch AND ProductName LIKE '%".$ProductName."%'";
$Hidden="";
$PageDetail="&Act=".$Act."&CatId=".$CatId."&New=".$New."&Promotion=".$Promotion."&ProductName=".$ProductName;
break;
}
?>
<?
$Check=Select($Table,$Condition);
$Num_Rows=Num_Rows($Check);
$Per_Page=12;
$Page=$_GET['Page'];
if(!$Page){
$Page=1;
}
$Page_Start=($Per_Page*$Page)-$Per_Page;
if($Num_Rows<=$Per_Page){
$Num_Pages=1;
}else if(($Num_Rows%$Per_Page)==0){
$Num_Pages=$Num_Rows/$Per_Page;
}else{
$Num_Pages=ceil($Num_Rows/$Per_Page);
}
$Num_Pages=(int)$Num_Pages;
$Select=Select($Table,"$Condition ORDER BY ProductId DESC LIMIT $Page_Start,$Per_Page");
$NoP=0;
echo "<table><tr>";
while($Product=mysql_fetch_array($Select)){
$NoP++;
echo "<td height=\"210\">";
?>
<table class="MouseOutProduct" id="Product<?=$NoP;?>" onmouseover="MouseOverProduct('Product<?=$NoP;?>');" onmouseout="MouseOutProduct('Product<?=$NoP;?>');">
<tr>
<td colspan="2"><div class="F-Object-Eng"><b><center><? echo iconv_substr($Product['ProductName'],0,20,"UTF-8");?></center></b></div></td>
</tr>
<tr>
<td colspan="2"><div class="F-Center"><img src="admin/picture/product/small-size/<?=$Product['Picture'];?>" /></div></td>
</tr>
<tr>
<td><div class="F-Object-Eng"><font size="2" color="#FF0000"><? echo "฿ ".number_format($Product['Price'],2,'.',','); ?></font></div></td>
<td><div class="F-Right">
<? if($Product['Promotion']=='Y'){ echo "<img src=\"admin/image/icon/promotion.png\" title=\"โปรโมชั่น\">";}
if($Product['New']=='Y'){ echo "<img src=\"admin/image/icon/new.png\" title=\"สินค้าใหม่\">";}?></div></td>
</tr>
<tr>
<td width="72"><div class="F-Object-Thai"><a href="detail.php?ProductId=<?=$Product['ProductId'];?>">รายละเอียด</a></div></td>
<td width="71"><div class="F-Right"><input type="button" class="Btn" value="ตระกร้า" onclick="window.location='cart.php?Act=Add&ProductId=<?=$Product['ProductId'];?>';"/></div></td>
</tr>
</table>
<?
if(($NoP%4)==0){
echo "<tr><td><tr>";
}else{
echo "<td width=\"8\">";
}
}
echo "</tr></table>";
?>
Tag : PHP, MySQL
ประวัติการแก้ไข 2017-11-16 14:54:42
Date :
2017-11-16 14:53:55
By :
TH.Ditsakorn
View :
680
Reply :
4
syntax Query น่าจะผิด ลองไล่ใน function.php ดูครับ น่าจะมีการสร้าง function build query อีกที อาจจะมีการต่อ string ผิด
Date :
2017-11-17 13:12:30
By :
mangkunzo
echo ตัวแปร query ออกมา แล้วเอาไปแปะใน phpMyadmin ดูครับ บางฟิลด์ หรือ คอลัมน์ ชนิดข้อมูลอาจจะเป็นแบบ specifiers ต้องกำหนด '' เข้าไปด้วย
Date :
2017-11-22 06:29:53
By :
Manussawin
รบกวนขอความช่วยเหลือครับ งมโข่งมา 1 อาทิตย์เต็มๆ ยังไม่ได้เลยครับ
product.php
<? error_reporting(0);
session_start();
include ('admin/module/connect.php');
include ('admin/module/function.php');?>
<!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>-: E-Commerce :-</title>
<link href="admin/css/style.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="admin/module/function.js"></script>
<script type="text/javascript">
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
</script>
</head>
<body>
<?
$Act=$_GET['Act'];
switch($Act){
case 'Category' : $Act=$_GET['Act'];
$CatId=$_GET['CatId'];
$Search=$_GET['Search'];
$SelectCat=Select("ecom_category","WHERE CatId='".$CatId."'");
$Cat=mysql_fetch_array($SelectCat);
$Title="PRODUCT : ".$Cat['CatName'];
$Table="ecom_product";
$Condition="WHERE CatId='".$CatId."'AND Quanlity > 0 AND ProductName LIKE '%".$Search."%'";
$Hidden="<input type=\"hidden\" name=\"Act\" value=\"$Act\"><input type=\"hidden\" name=\"CatId\" value=\"$CatId\">";
$PageDetail="&Act=".$Act."&CatId=".$CatId."&Search=".$Search;
break;
case 'Product' : $Act=$_GET['Act'];
$Search=$_GET['Search'];
$Title="TOTAL PRODUCT";
$Table="ecom_Product";
$Condition="WHERE ProductName LIKE '%".$Search."%'AND Quanlity > 0";
$Hidden="<input type=\"hidden\" name=\"Act\" value=\"$Act\">";
$PageDetail="&Act=".$Act."&Search=".$Search;
break;
case 'New' : $Act=$_GET['Act'];
$New=$_GET['New'];
$Search=$_GET['Search'];
$Title="NEW PRODUCTS";
$Table="ecom_product";
$Condition="WHERE New='".$New."'AND Quanlity > 0 AND ProductName LIKE '%".$Search."%'";
$Hidden="<input type=\"hidden\" name=\"Act\" value=\"$Act\"><input type=\"hidden\" name=\"New\" value=\"$New\">";
$PageDetail="&Act=".$Act."&New=".$New."&Search=".$Search;
break;
case 'Promotion': $Act=$_GET['Act'];
$Promotion=$_GET['Promotion'];
$Search=$_GET['Search'];
$Title="PROMOTION PRODUCT";
$Table="ecom_product";
$Condition="WHERE Promotion='".$Promotion."'AND Quanlity > 0 AND ProductName LIKE '%".$Search."%'";
$Hidden="<input type=\"hidden\" name=\"Act\" value=\"$Act\"><input type=\"hidden\" name=\"Promotion\" value=\"$Promotion\">";
$PageDetail="&Act=".$Act."&Promotion=".$Promotion."&Search=".$Search;
break;
case 'ProductSearch' : $Act=$_GET['Act'];
$CatId=$_GET['CatId'];
$New=$_GET['New'];
$Promotion=$_GET['Promotion'];
$ProductName=$_GET['ProductName'];
$Title="Search Products";
if($CatId != ''){
$CatIdSearch="CatId='".$CatId."'";
}else{
$CatIdSearch="CatId LIKE '%".$CatId."%'";
}
if($New != ""){
$NewSearch="New='".$New."'";
}else{
$NewSearch="New LIKE '%".$New."%'";
}
if($Promotion != ""){
$PromotionSearch="Promotion='".$Promotion."'";
}else{
$PromotionSearch="Promotion LIKE '%".$Promotion."%'";
}
$Table="ecom_product";
$Condition="WHERE $CatIdSearch AND Quanlity > 0 AND $NewSearch AND $PromotionSearch AND ProductName LIKE '%".$ProductName."%'";
$Hidden="";
$PageDetail="&Act=".$Act."&CatId=".$CatId."&New=".$New."&Promotion=".$Promotion."&ProductName=".$ProductName;
break;
}
?>
<div id="divSwap">
<div id="divLogo"></div>
<div id="divMenu"><? include ('menu.php');?></div>
<div id="divStyle">
<div id="divLoginOutLine">
<div id="divLoginInLine">
<? include('login.php');?>
</div>
</div>
<div id="divMenuCatOutLine">
<div id="divMenuCatInLine">
<? include('menu_category.php'); ?>
</div>
</div>
<div id="divNewOutLine">
<div id="divNewInLine">
</div>
</div>
<div id="divPromotionOutLine">
<div id="divPromotionInLine"></div>
</div>
<div id="divFullTitle">
<table width="100%" border="0">
<tr>
<td><div class="F-BL-Title"><? echo $Title; ?></div></td>
</tr>
<tr>
<td><img src="admin/image/line/line-full.png" width="670" height="5" /></td>
</tr>
</table>
</div>
<div id="divFullNoLine">
<?
$Check=Select($Table,$Condition);
$Num_Rows=Num_Rows($Check);
$Per_Page=12;
$Page=$_GET['Page'];
if(!$Page){
$Page=1;
}
$Page_Start=($Per_Page*$Page)-$Per_Page;
if($Num_Rows<=$Per_Page){
$Num_Pages=1;
}else if(($Num_Rows%$Per_Page)==0){
$Num_Pages=$Num_Rows/$Per_Page;
}else{
$Num_Pages=ceil($Num_Rows/$Per_Page);
}
$Num_Pages=(int)$Num_Pages;
$Select=Select($Table,"$Condition ORDER BY ProductId DESC LIMIT $Page_Start,$Per_Page");
$NoP=0;
echo "<table><tr>";
while($Product=mysql_fetch_array($Select)){
$NoP++;
echo "<td height=\"210\">";
?>
<table class="MouseOutProduct" id="Product<?=$NoP;?>" onmouseover="MouseOverProduct('Product<?=$NoP;?>');" onmouseout="MouseOutProduct('Product<?=$NoP;?>');">
<tr>
<td colspan="2"><div class="F-Object-Eng"><b><center><? echo iconv_substr($Product['ProductName'],0,20,"UTF-8");?></center></b></div></td>
</tr>
<tr>
<td colspan="2"><div class="F-Center"><img src="admin/picture/product/small-size/<?=$Product['Picture'];?>" /></div></td>
</tr>
<tr>
<td><div class="F-Object-Eng"><font size="2" color="#FF0000"><? echo "฿ ".number_format($Product['Price'],2,'.',','); ?></font></div></td>
<td><div class="F-Right">
<? if($Product['Promotion']=='Y'){ echo "<img src=\"admin/image/icon/promotion.png\" title=\"โปรโมชั่น\">";}
if($Product['New']=='Y'){ echo "<img src=\"admin/image/icon/new.png\" title=\"สินค้าใหม่\">";}?></div></td>
</tr>
<tr>
<td width="72"><div class="F-Object-Thai"><a href="detail.php?ProductId=<?=$Product['ProductId'];?>">รายละเอียด</a></div></td>
<td width="71"><div class="F-Right"><input type="button" class="Btn" value="ตระกร้า" onclick="window.location='cart.php?Act=Add&ProductId=<?=$Product['ProductId'];?>';"/></div></td>
</tr>
</table>
<?
if(($NoP%4)==0){
echo "<tr><td><tr>";
}else{
echo "<td width=\"8\">";
}
}
echo "</tr></table>";
?>
<div id="divSearch">
<? if($Act=='ProductSearch'){}else{?>
<form action="?" method="get">
<table width="100" border="0">
<tr>
<td><input type="search" class="Input" name="Search" id="Search" value="" /><? echo $Hidden; ?>
</td>
<td><input type="image" src="admin/image/icon/search.png" /></td>
</tr>
</table>
</form>
<? } ?>
</div>
<div id="divPage">
<table width="676" border="0">
<tr>
<td width="408"> </td>
<td width="85"><div class="F-Object-Thai">สินค้าทั้งหมด</div></td>
<td width="76"><div class="F-Object-Thai"><? echo $Num_Rows." เรือน";?></div></td>
<td width="89">
<select class="JumgMenu" name="Page" id="Page" onchange="MM_jumpMenu('parent',this,0)">
<?
for($i=1;$i<=$Num_Pages;$i++){
if($Page==$i){
$SelP="selected";
}else{
$SelP="";
}
?>
<option value="?Page=<?=$i.$PageDetail;?>" <?=$SelP;?>><?=$i;?></option>
<? } ?>
</select>
</td>
</tr>
</table>
</div>
</div>
<div id="divToolPage">
<table width="685" border="0">
<tr>
<td width="66"><div class="F-BC-Title"><? if($Page==1){}else{ $BackPage=$Page-1; echo "<a href=\"?Page=$BackPage$PageDetail\"><img src=\"admin/image/icon/left.png\" border=\"0\" /> ย้อนกลับ</a>"; }?></div></td>
<td width="546"> </td>
<td width="52"><div class="F-BC-Title"><? if($Page==$Num_Pages){}else{ $NextPage=$Page+1; echo "<a href=\"?Page=$NextPage$PageDetail\">ถัดไป <img src=\"admin/image/icon/right.png\" border=\"0\" /></a>";}?></div></td>
</tr>
</table>
</div>
</div>
<div id="divFooter"><? include('footer.php');?></div>
</div>
</body>
</html>
function.php
<?
//========= Function Insert Data =========
function Insert($Table,$Field,$Value){
$Insert=mysql_query("INSERT INTO $Table ($Field) VALUES ($Value)") or die (mysql_error());
return $Insert;
}
//========= Function Select Data (WHERE) =========
function Select($Table,$Condition){
$Select=mysql_query("SELECT * FROM $Table $Condition ") or die (mysql_error());
return $Select;
}
//========= Function Delete Data (WHERE) =========
function Delete($Table,$Condition){
$Delete=mysql_query("DELETE FROM $Table $Condition ") or die (mysql_error());
return $Delete;
}
//========= Function Update Data (WHERE) =========
function Update($Table,$Condition){
$Update=mysql_query("UPDATE $Table SET $Condition") or die (mysql_error());
return $Update;
}
//========= Function Num_Rows (WHERE) =========
function Num_Rows($Condition){
$Num_Rows=mysql_num_rows($Condition);
return $Num_Rows;
}
//========= Function ResizePicture) =========
function ResizePicture($Picture_Tmp,$Rename,$Height,$Path){
$Size=getimagesize($Picture_Tmp);
$SizeX=$Size[0];
$SizeY=$Size[1];
$Weight=ceil($SizeX*$Height)/$SizeY;
$Image_Fin=imagecreatetruecolor($Weight,$Height);
$Image_Ori=imagecreatefrompng($Picture_Tmp);
$ImageX=imagesx($Image_Ori);
$ImageY=imagesy($Image_Ori);
imagecopyresampled($Image_Fin,$Image_Ori,0,0,0,0,$Weight,$Height,$ImageX,$ImageY);
imagepng($Image_Fin,$Path.$Rename);
imagedestroy($Image_Fin);
imagedestroy($Image_Ori);
$Complete="Complete";
return $Complete;
}
?>
Date :
2017-11-27 16:50:43
By :
TH.Ditsakorn
<? error_reporting(0); เอาออกซะถ้าอยากจะหา error
และ<? เปลี่ยนไปใช้แบบเต็มให้เคยชิน <?PHP
mysql ก็เลิกใช้ให้ใช้ mysqli ได้แล้วล่ะครับ php version ไหนครับ
พอใช้งาน host จริง น่าจะมีปัญหา เพราะคิดว่าเขาน่าจะใช้ของใหม่กันหมดแล้ว
ยกเว้นพวก server เก่าๆ ที่ยังมีลูกค้าเก่าๆอยู่
Date :
2017-11-27 21:32:46
By :
Chaidhanan
Load balance : Server 02