รบกวนถามปัญหาค่ะ You have an error in your SQL syntax; check the manual that corresponds to your MySQL server
รบกวนช่วยดูให้หน่อยค่ะ มีปัญหาตอน เพิ่มข้อมูล มัน่ขึ้นแบบนี้อ่ะค่ะ
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
ตอนแก้ไขข้อมูลก็ขึ้นแบบนี้อ่ะค่ะ
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 ' `3_12b`= WHERE id_sdomes=1' at line 1
พอดีเพิ่งเข้ามาทำงานที่นี้ที่แรก ต้องมานั่งงมโค้ดของคนอื่น อ่ะค่ะ ่ยังไม่มีประสบการณ์เลย รบกวนช่วยหน่อยนะค่ะ
Code (PHP)
<?
session_start();
ob_start();
require_once('../Connections/panfan.php');
?>
<script language="Javascript1.2"><!-- // load htmlarea
_editor_url = ""; // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera') >= 0) { win_ie_ver = 0; }
if (win_ie_ver >= 5.5) {
document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
document.write(' language="Javascript1.2"></scr' + 'ipt>');
} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }
// --></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>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620">
<link href="../css.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {color: #333333}
.style4 {color: #FFFFFF}
.style5 {color: #FFFFFF; font-weight: bold; }
.style6 {font-weight: bold}
-->
</style>
<p align="center"><font size="2" face="MS Sans Serif, Tahoma, sans-serif">
<?
$dd=date("Ymdhis");
if($funtion=='add'){
$a_dsp = sprintf("INSERT INTO domes_sprice (id_sdomes, id_domes_ref, val, val_en, 1a, 3_12nob,3_12b) VALUES (0,%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['id_domes_ref'], "int"),
// GetSQLValueString($_POST['id_hotel_ref'], "int"),
GetSQLValueString($_POST['val'], "text"),
GetSQLValueString($_POST['val_en'], "text"),
GetSQLValueString($_POST['1a'], "float"),
GetSQLValueString($_POST['3_12a'], "float"),
GetSQLValueString($_POST['3_12b'], "float"));
$result1 = mysql_query($a_dsp)or die(mysql_error());
echo"<br><br>ทำการเพิ่มข้อมูลแล้วครับ<meta http-equiv=refresh content=0;URL=?page_a=$page_a >";
} else if($funtion=='edit'){
$e_sdomes = sprintf("UPDATE domes_sprice SET `id_domes_ref`=%s,`val`=%s,`val_en`=%s,`1a`=%s,`3_12nob`=%s, `3_12b`=%s WHERE id_sdomes=%s",
GetSQLValueString($_POST['id_domes_ref'], "int"),
// GetSQLValueString($_POST['id_domes_ref'], "int"),
GetSQLValueString($_POST['val'], "text"),
GetSQLValueString($_POST['val_en'], "text"),
GetSQLValueString($_POST['1a'], "float"),
GetSQLValueString($_POST['3_12nob'], "float"),
GetSQLValueString($_POST['3_12b'], "float"),
GetSQLValueString($_GET['id'], "int"));
$result1 = mysql_query($e_sdomes) or die(mysql_error());
echo"<br><br>ทำการแก้ไขข้อมูลแล้วครับ <meta http-equiv=refresh content=0;URL=?page_a=$page_a >";
}
else if($funtion=='dele'){
$sql="delete from domes_sprice where id_sdomes='$id'";
$db_query=mysql_query($sql);
print "<br><br>ทำการลบข้อมูลแล้วครับ<meta http-equiv=refresh content=0;URL=?page_a=$page_a >";
?>
</span></font></p>
<div align="left"><font size="2" face="MS Sans Serif, Tahoma, sans-serif">
<? } else if($funtion=='form'){?>
</p>
</div>
<span class="txtblue01"><strong>ระบบจัดการ Domestic Package Saling Price </strong><br />
<br>
</div>
</span>
<table width="98%" border="0" cellpadding="2" cellspacing="1">
<?
if($f_edit=='f_edit')
{
$sql=mysql_query("select * from domes_sprice where id_sdomes='$id' ");
$result2=mysql_fetch_array($sql);
//$str = str_replace(chr(132), '"', $l['z_name']); // baseline double quote
echo"<form name=\"form2\" method=\"post\" action=\"?page_a=$page_a&funtion=edit&id=".$result2['id_sdomes']."\" enctype=\"multipart/form-data\">";}
else
{echo"<form name=\"form2\" method=\"post\" action=\"?page_a=$page_a&funtion=add&id=".$id."\" enctype=\"multipart/form-data\">";}
?>
<tr bgcolor="#DFDFDF">
<td height="26" colspan="3" bgcolor="#73B3F2" class="txt12gray"><div align="center" class="style5"><font size="2" face="MS Sans Serif, Tahoma, sans-serif"><span class="style3">
<?
if($f_edit=='f_edit') {echo"แก้ไข";}
else {echo"เพิ่ม";}
?>
</span></font></div></td>
</tr>
<tr>
<td align="center" valign="middle" bgcolor="#3399FF" class="txt12gray"><strong class="txt13yellow">Package</strong></td>
<td colspan="2" bgcolor=""><div align="left"><font size="2" face="MS Sans Serif, Tahoma, sans-serif">
<label></label>
<select name="id_domes_ref">
<?php
$sql_show_domes =mysql_query("select * from domestic order by id_domes asc");
$num_rows_domes=mysql_num_rows($sql_show_domes);
$no_domes=1;
while($domes=mysql_fetch_array($sql_show_domes)){
if($no_domes==1){
?>
<option value="">--- กรุณาเลือกแพคเกจ ---</option>
<?php }
$id_domes= $domes[id_domes];
$name_domes = $domes[name];
?>
<option value="<?php echo "$id_domes"; ?>"
<?php if($f_edit=='f_edit') {
if($id_domes==$result2[id_domes_ref]) { echo "selected"; } }
else {
if($domes["id_domes"]==$id) {echo"selected";}}?>
><? echo "$name_domes"; ?></option>
<?php $no_domes++; } ?>
</select>
</font></div></td>
</tr>
<tr>
<td width="22%" align="center" valign="middle" bgcolor="#3399FF" class="txt12gray"><strong class="txt13yellow">ช่วงวันเวลา</strong></td>
<td colspan="2" bgcolor=""><div align="left"><font size="2" face="MS Sans Serif, Tahoma, sans-serif">
<input name="val" type="text" id="val" value="<?php if($f_edit=='f_edit') {echo"".$result2['val']."";}?>" size="100" />
<label></label>
</font></div></td>
</tr>
<tr>
<td width="22%" align="center" valign="middle" bgcolor="#3399FF" class="txt12gray"><strong class="txt13yellow">Validity</strong></td>
<td colspan="2" bgcolor=""><div align="left"><font size="2" face="MS Sans Serif, Tahoma, sans-serif">
<input name="val_en" type="text" id="val_en" value="<?php if($f_edit=='f_edit') {echo"".$result2['val_en']."";}?>" size="100" />
<label></label>
</font></div></td>
</tr>
<tr>
<td align="center" valign="middle" bgcolor="#3399FF" class="txt13yellow">AGE</td>
<td align="center" valign="middle" bgcolor="#3366FF" class="txt11yellow">Adult</td>
<tr>
<td align="center" valign="middle" bgcolor="#3399FF" class="txt12gray"><strong>ผู้ใหญ่</strong></td>
<td width="78%" bgcolor=""><div align="left"><font size="2" face="MS Sans Serif, Tahoma, sans-serif">
<input name="1a" type="text" id="1a" value="<?php if($f_edit=='f_edit') {echo"".$result2['1a']."";}?>" size="25" />
</font></div> <font size="2" face="MS Sans Serif, Tahoma, sans-serif"><label></label>
</font></td>
</tr>
<tr>
<td align="center" valign="middle" bgcolor="#3399FF" class="txt12gray"><strong>เด็ก 3 - 12 ปี (ไม่มีเตียงเสริม)</strong></td>
<td bgcolor=""><div align="left"><font size="2" face="MS Sans Serif, Tahoma, sans-serif">
<label>
<input name="2_3a" type="text" id="2_3a" value="<?php if($f_edit=='f_edit') {echo"".$result2['3_12nob']."";}?>" size="25" />
</label>
</font></div></td>
</tr>
<tr>
<td align="center" valign="middle" bgcolor="#3399FF" class="txt12gray"><strong>เด็ก 3 - 12 ปี (มีเตียงเสริม)</strong></td>
<td bgcolor=""><div align="left"><font size="2" face="MS Sans Serif, Tahoma, sans-serif">
<label>
<input name="4_9a" type="text" id="4_9a" value="<?php if($f_edit=='f_edit') {echo"".$result2['3_12b']."";}?>" size="25" />
</label>
</font></div></td>
< </tr>
<tr> </tr>
<tr bgcolor="#DFDFDF">
<td colspan="3" bgcolor="#73B3F2"><div align="center"> <font size="2" face="MS Sans Serif, Tahoma, sans-serif">
<?
if($f_edit=='f_edit') {echo"<input type=\"submit\" name=\"Submit\" value=\"แก้ไข\">";}
else {echo"<input type=\"submit\" name=\"Submit\" value=\"เพิ่ม\">";}
?>
</font></div></td>
</tr>
<? echo"</form>"; ?>
</table>
<div align="left"><font size="2" face="MS Sans Serif, Tahoma, sans-serif"><br>
<? } else {?>
<div align="left"><font size="2" face="MS Sans Serif, Tahoma, sans-serif">
</font> <span class="txtblue01"><strong>ระบบจัดการ Domestic Package Saling Price</strong></span><br />
<br>
</div>
<table width="98%" border="0" cellpadding="3" cellspacing="1">
<form name="form1s"><tr>
<td colspan="9" bgcolor="#F0F8FF">
<font size="2" face="MS Sans Serif, Tahoma, sans-serif">
<div align="center" class="txt12gray style1"><font size="2" face="MS Sans Serif, Tahoma, sans-serif">
<select name="id_domes" onChange="MM_jumpMenu('parent',this,0)">
<option value="?page_a=<? echo $page_a?>"> --- เลือก Package --- </option>
<?
$sql_jump = "SELECT * FROM domestic order by name asc";
$query_jump = mysql_query($sql_jump) or die("select error = $sql_jump");
$num_jump = mysql_num_rows($query_jump);
for($i=1;$i<=$num_jump;$i++)
{
$row_jump = mysql_fetch_array($query_jump);
?>
<option value="?page_a=<? echo $page_a?>&id=<?=$row_jump['id_domes']?>" <? if($row_jump['id_domes']==$_GET['id']){ echo "selected"; } ?>>
<?=$row_jump['name']?>
</option>
<?
}
?>
</select>
</font>[ <a href="?page_a=<? echo "$page_a";?>">ดูทั้งหมด</a> ]</div> </tr>
</form>
<?
if($id=="") { //ข้อมูลของ Val ที่ตรงกับ
$strSQL="select * from domes_sprice order by id_sdomes desc";
} else {
$strSQL="select * from domes_sprice where id_domes_ref='".$id."' order by id_sdomes desc";
}
$Per_Page = 20;
if ( !$Page )
$Page = 1;
$Prev_Page = $Page - 1;
$Next_Page = $Page + 1;
$resultg = mysql_query($strSQL);
$Page_start = ( $Per_Page * $Page ) - $Per_Page;
$Num_Rows = mysql_num_rows( $resultg );
if ( $Num_Rows <= $Per_Page )
$Num_Pages = 1;
else if ( ( $Num_Rows % $Per_Page ) == 0 )
$Num_Pages = ( $Num_Rows / $Per_Page );
else
$Num_Pages = ( $Num_Rows / $Per_Page ) + 1;
$Num_Pages = ( int ) $Num_Pages;
if ( ( $Page > $Num_Pages ) || ( $Page < 0 ) )
print "จำนวน $Page มากกว่า $Num_Pages";
$strSQL .= " LIMIT $Page_start, $Per_Page";
$allPage = ceil($Num_Rows/$Per_Page);
if(isset($_GET['Page'])){
$Page = $_GET['Page'];
$topage = $Page-1;
}else{
$topage = 0;
$Page = 1;
}
$linkpage = "<a href='".$_SERVER['PHP_SELF']."?Page=1&page_a=$page_a&hotel=$hotel' title='ไปหน้าแรก' class='txtorg12b'>[ Prev ]</a> ";
if($Page<6){
$i=1;
$allPage<11 ? $doLoop = $allPage : $doLoop = 11;
while($i<=$doLoop){
if($i==$Page){
$linkpage .= "<span class='box'><b>$i</b></span> ";
}else{
$linkpage .= "<a href='".$_SERVER['PHP_SELF']."?Page=$i&page_a=$page_a&hotel=$hotel' class='txtorg12b'>$i</a> ";
}
$i++;
}
}elseif( ($allPage-$Page) < 6){
$allPage<11 ? $start = 1 : $start = $allPage-10;
for($i=$start;$i<=$allPage;$i++){
if($i==$Page){
$linkpage .= "<span class='box'><b>$i</b></span> ";
}else{
$linkpage .= "<a href='".$_SERVER['PHP_SELF']."?$temp&Page=$i&page_a=$page_a&hotel=$hotel' class='txtorg12b'>$i</a> ";
}
}
}else{
for($i=$Page-5;$i<=$Page+5;$i++){
if($i==$Page){
$linkpage .= "<span class='box'><b>$i</b></span> ";
}else{
$linkpage .= "<a href='".$_SERVER['PHP_SELF']."?Page=$i&page_a=$page_a&hotel=$hotel' class='txtorg12b'>$i</a> ";
}
}
}
$linkpage .= "<a href='".$_SERVER['PHP_SELF']."?Page=$allPage&page_a=$page_a&hotel=$hotel' title='ไปหน้าสุดท้าย' class='txtorg12b'>[ Last ]</a>";
?>
<tr>
<td colspan="9" bgcolor="#F0F8FF"><div align="left"><font size="2" face="MS Sans Serif, Tahoma, sans-serif"><a href="?page_a=<? echo"$page_a";?>&id=<? echo"$id";?>&package=<? echo $package;?>&funtion=form" class="txt12gray style1"><strong>+ เพิ่ม Saling Price </strong></a></font></div>
<div align="left"></div></td>
</tr>
<? ?>
<tr>
<th rowspan="2" width="340" bgcolor="#73B3F2"><div align="center" class="style4"><font size="2" face="MS Sans Serif, Tahoma, sans-serif"><strong><strong>Validity</strong></strong></font></div></th>
<th colspan="7" bgcolor="#996666"><div align="center" class="style4"><font size="2" face="MS Sans Serif, Tahoma, sans-serif"><strong><strong>Saling Price</strong></strong></font></div></th>
</tr>
<tr>
<td width="95" bgcolor="#0099FF"><div align="center" class="style4"><strong><font size="1" face="MS Sans Serif, Tahoma, sans-serif">ผู้ใหญ่</font></strong></div></td>
<td width="95" bgcolor="#0099FF"><div align="center" class="style4"><strong><font size="1" face="MS Sans Serif, Tahoma, sans-serif">เด็ก 3 - 12 (ไม่มีเตียงเสริม)</font></strong></div></td>
<td width="95" bgcolor="#0099FF"><div align="center" class="style4"><strong><font size="1" face="MS Sans Serif, Tahoma, sans-serif">เด็ก 3 - 12 (มีเตียงเสริม)</font></strong></div></td>
<td width="65" bgcolor="#006699"><div align="center" class="style4"><strong><font size="2" face="MS Sans Serif, Tahoma, sans-serif">แก้ไข</font></strong></div></td>
<td width="65" bgcolor="#006699"><div align="center" class="style4"><strong><font size="2" face="MS Sans Serif, Tahoma, sans-serif">ลบ</font></strong></div></td>
</tr>
<?
if($Num_Rows==0){
?>
<tr bgcolor="">
<td colspan="19" bgcolor="#FFFFCC"><div align="center"><font size="2" face="MS Sans Serif, Tahoma, sans-serif"><span class="style6">ยังไม่มีข้อมูลครับ</span></font></div></td>
</tr>
<?
} else {
$sql_show = mysql_query($strSQL);
$num_rows_val = mysql_num_rows($sql_show);
$no_v=1;
while($result2=mysql_fetch_array($sql_show)){
$sql_domes=mysql_query("select * from domestic where id_domes='".$result2['id_domes_ref']."'");
$num_rows_domes=mysql_num_rows($sql_domes);
if($num_rows_domes == 0) {$dd = "";}
else {
$_domes=mysql_fetch_array($sql_domes);
$dd = $_domes['name'];
}
//ต้องกำหนดไม่ให้ซ้ำซ้อนกับของเดิม
if(($no_v % 2)==0){ $bgcolor = "#F0F8FF";
}else{
$bgcolor = "#F9F9F9";
} //สีแรก
?>
<tr bgcolor="">
<td height="20" rowspan="2" scope="row" bgcolor="<? echo $bgcolor;?>" class="txtred12"><div align="left"><font size="2" face="MS Sans Serif, Tahoma, sans-serif">[ <? echo $dd;?> ] <? echo"".$result2['val']."";?></font></div></td>
<td bgcolor="#FFFFB3"><div align="center"><font size="2" face="MS Sans Serif, Tahoma, sans-serif"><? echo"".$result2['1a']."";?></font></div></td>Code (PHP)
[php]Code (PHP)
[php]
[/php]
<td bgcolor="#FFFFB3"><div align="center"><font size="2" face="MS Sans Serif, Tahoma, sans-serif"><? echo"".$result2['3_12nob']."";?></font></div></td>
<td bgcolor="#FFFFB3"><div align="center"><font size="2" face="MS Sans Serif, Tahoma, sans-serif"><? echo"".$result2['3_12b']."";?></font></div></td>
<td rowspan="2" bgcolor="#E8E8E8"><div align="center"><font size="2" face="MS Sans Serif, Tahoma, sans-serif"><span class="style6"><a href="?page_a=<? echo"$page_a";?>&funtion=form&f_edit=f_edit&id=<? echo"".$result2['id_sdomes']."";?>">แก้ไข</a></span></font></div></td>
<td rowspan="2" bgcolor="#E8E8E8"><div align="center"><font size="2" face="MS Sans Serif, Tahoma, sans-serif"><span class="style6"><a href="?page_a=<? echo"$page_a";?>&funtion=dele&id=<? echo"".$result2['id_sdomes']."";?>">ลบ</a></span></font></div> </td>
</tr>
<tr bgcolor="">
</tr>
<? $no_v++;} } ?>
</table>
</div> <? }
mysql_close(); ?>
</body>
</html>
[/php]
****************-------------------------*******************
ส่วนนี้คือตารางที่ต้องใส่อ่ะค่ะ
--
-- Table structure for table `domes_sprice`
--
CREATE TABLE IF NOT EXISTS `domes_sprice` (
`id_sdomes` int(10) NOT NULL auto_increment,
`id_domes_ref` int(10) NOT NULL,
`val` varchar(200) NOT NULL,
`val_en` varchar(200) NOT NULL,
`1a` float NOT NULL,
`3_12nob` float NOT NULL,
`3_12b` float NOT NULL,
PRIMARY KEY (`id_sdomes`)
) ENGINE=MyISAM DEFAULT CHARSET=tis620 ROW_FORMAT=DYNAMIC AUTO_INCREMENT=2 ;
--
-- Dumping data for table `domes_sprice`Tag : PHP, MySQL
Date :
2011-03-30 10:23:33
By :
panfantour
View :
1966
Reply :
3
คิดว่า 3_12b ไม่มีค่า
ลองเปลี่ยน
$result1 = mysql_query($e_sdomes) or die(mysql_error());
เป็น
$result1 = mysql_query($e_sdomes) or die(mysql_error() . '' . $e_sdomes);
จะได้เป็น sql statement ด้วย
Date :
2011-03-30 10:34:33
By :
PlaKriM
ลองทำตามที่พี่บอกแล้วนะค่ะแต่ัมันก็ขึ้นแบบนี้
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 ' `3_12b`= WHERE id_sdomes=1' at line 1UPDATE domes_sprice SET `id_domes_ref`=1, `val`='ffff',`val_en`='ffff',`1a`=2222,`3_12nob`=, `3_12b`= WHERE id_sdomes=1
แก้ตรงไหนดีอ่ะค่ะ
Date :
2011-03-30 10:45:52
By :
panfantour
$e_sdomes = sprintf("UPDATE domes_sprice SET `id_domes_ref`='%s',`val`='%s',`val_en`='%s',`1a`='%s',`3_12nob`='%s', `3_12b`='%s' WHERE id_sdomes='%s'",
ใส่ ' เข้าไปครอบครับ ไม่รู้จะได้ผลหรือเปล่านะไม่เคยใช้ื dream gen ให้แบบนี้
Date :
2011-03-30 11:02:58
By :
PlaKriM
Load balance : Server 02