(แก้ได้แล้วค่า) ติด error in your SQL syntax; check the manual that corresponds to your MySQL server version
พอดีเอาโค้ดมาจาก https://www.thaicreate.com/windows-azure/windows-azure-web-site-php-mysql-insert-update-delete.html ค่ะ
แล้วก็แก้ไขโฮสกับดาต้าเบสของตัวเอง
กด delete / edit-> cancel ได้ค่ะ
แต่กด edit -> update ไม่ได้ มันขึ้นมาว่า
Error Update [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 'group = 'work' ,WHERE name = 'dklfm'' at line 1]
อันนี้ข้อมูลดาต้าเบสในเครื่องนะคะ
อันนี้โค้ดค่ะ
Code (PHP)
<html>
<head>
<title></title>
</head>
<body>
<?php
// ********************================ PHP ===================
$host = "ap-cdbr-azure-southeast-b.cloudapp.net";
$username = "b0bd3a2ee2945";
$password = "5d68f2759";
$objConnect = mysql_connect($host,$username,$password);
$objDB = mysql_select_db("namecard");
//*** Add Condition ***//
if($_POST["hdnCmd"] == "Add")
{
$strSQL = "INSERT INTO contact ";
$strSQL .="(name,email,telephone,street,city,state,zip,contry,group) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["txtAddName"]."','".$_POST["txtAddEmail"]."','".$_POST["txtAddPhone"]."' ";
$strSQL .=",'".$_POST["txtAddStreet"]."','".$_POST["txtAddCity"]."','".$_POST["txtAddState"]."','".$_POST["txtAddZip"]."','".$_POST["txtAddCountry"]."','".$_POST["txtAddGroup"]."') ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Save [".mysql_error()."]";
}
}
//*** Update Condition ***//
if($_POST["hdnCmd"] == "Update")
{
$strSQL = "UPDATE contact SET ";
$strSQL .="name = '".$_POST["txtEditName"]."' ";
$strSQL .=",email = '".$_POST["txtEditEmail"]."' ";
$strSQL .=",telephone = '".$_POST["txtEditPhone"]."' ";
$strSQL .=",street = '".$_POST["txtEditStreet"]."' ";
$strSQL .=",city = '".$_POST["txtEditCity"]."' ";
$strSQL .=",state = '".$_POST["txtEditState"]."' ";
$strSQL .=",zip = '".$_POST["txtEditZip"]."' ";
$strSQL .=",contry = '".$_POST["txtEditCountry"]."' ";
$strSQL .=",group = '".$_POST["txtEditGroup"]."' ";
$strSQL .=" WHERE name = '".$_POST["hdnEditCustomer"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Update [".mysql_error()."]";
}
}
//*** Delete Condition ***//
if($_GET["Action"] == "Del")
{
$strSQL = "DELETE FROM contact ";
$strSQL .="WHERE name = '".$_GET["name"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Delete [".mysql_error()."]";
}
}
$strSQL = "SELECT * FROM contact";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<form name="frmMain" method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">
<input type="hidden" name="hdnCmd" value="">
<br><br><table width="600" border="1">
<tbody><tr>
<th width="70"> <div align="center"><font color="orange">Name</font></div></th>
<th width="100"> <div align="center"><font color="orange">Email</font> </div></th>
<th width="70"> <div align="center"><font color="orange">Telephone</font> </div></th>
<th width="50"> <div align="center"><font color="orange">Street</font> </div></th>
<th width="50"> <div align="center"><font color="orange">City</font> </div></th>
<th width="80"> <div align="center"><font color="orange">State</font> </div></th>
<th width="50"> <div align="center"><font color="orange">Zipcode</font> </div></th>
<th width="80"> <div align="center"><font color="orange">Country</font> </div></th>
<th width="50"> <div align="center"><font color="orange">Group</font> </div></th>
<th width="50"> <div align="center"><i class="fa fa-fw fa-pencil text-danger"></i></div></th>
<th width="50"> <div align="center"><i class="fa fa-fw fa-trash text-danger"></i></div></th>
</tr>
<?php
while($objResult = mysql_fetch_array($objQuery))
{
?>
<?php
if($objResult["name"] == $_GET["name"] and $_GET["Action"] == "Edit")
{
?>
<tr>
<td><div align="center">
<input type="text" name="txtEditName" size="5" value="<?php echo $objResult["name"];?>">
<input type="hidden" name="hdnEditCustomer" size="5" value="<?php echo $objResult["name"];?>">
</div></td>
<td><input type="text" name="txtEditEmail" size="20" value="<?php echo $objResult["email"];?>"></td>
<td><div align="center"><input type="text" name="txtEditPhone" size="10" value="<?php echo $objResult["telephone"];?>"></div></td>
<td><input type="text" name="txtEditStreet" size="5" value="<?php echo $objResult["street"];?>"></td>
<td><input type="text" name="txtEditCity" size="5" value="<?php echo $objResult["city"];?>"></td>
<td><input type="text" name="txtEditState" size="5" value="<?php echo $objResult["state"];?>"></td>
<td><input type="text" name="txtEditZip" size="5" value="<?php echo $objResult["zip"];?>"></td>
<td><input type="text" name="txtEditCountry" size="5" value="<?php echo $objResult["contry"];?>"></td>
<td><input type="text" name="txtEditGroup" size="5" value="<?php echo $objResult["group"];?>"></td>
<td colspan="2" align="right"><div align="center">
<input name="btnAdd" type="button" id="btnUpdate" value="Update" onclick="frmMain.hdnCmd.value='Update';frmMain.submit();">
<input name="btnAdd" type="button" id="btnCancel" value="Cancel" onclick="window.location='<?php echo $_SERVER["php_self"];?>';">
</div></td>
</tr>
<?php
}
else
{
?>
<tr>
<td><?php echo $objResult["name"];?></td>
<td><?php echo $objResult["email"];?></td>
<td><div align="center"><?php echo $objResult["telephone"];?></div></td>
<td align="right"><?php echo $objResult["street"];?></td>
<td align="right"><?php echo $objResult["city"];?></td>
<td align="right"><?php echo $objResult["state"];?></td>
<td align="right"><?php echo $objResult["zip"];?></td>
<td align="right"><?php echo $objResult["contry"];?></td>
<td align="right"><?php echo $objResult["group"];?></td>
<td align="center"><a href="<?php echo $_SERVER["PHP_SELF"];?>?Action=Edit&name=<?php echo $objResult["name"];?>">Edit</a></td>
<td align="center"><a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?php echo $_SERVER["PHP_SELF"];?>?Action=Del&name=<?php echo $objResult["name"];?>';}">Delete</a></td>
</tr>
<?php
}
?>
<?php
}
?>
<?php
mysql_close($objConnect);
// ********************================ PHP ===================
?>
</body>
</html>
[font=Verdana]แก้ได้แล้วค่า [/font]
$strSQL .=",group = '".$_POST["txtEditGroup"]."' ";
เปลี่ยนจาก group -> groupp (ชื่อไรก็ได้ค่ะ)
group เป็นคำสงวนเลยใส่ค่าไม่เข้าTag : PHP, MySQL, Windows Azure
ประวัติการแก้ไข 2016-12-23 09:48:16 2016-12-23 09:49:18 2016-12-23 10:09:15 2016-12-23 10:23:14
Date :
2016-12-23 08:14:33
By :
nutmut
View :
994
Reply :
4
$strSQL .=" WHERE name = '".$_POST["hdnEditCustomer"]."' ";
ตรง Where ไม่ต้องใส่ลูกน้ำครับ ตัดออก
Date :
2016-12-23 08:26:09
By :
deawx
echo $strSQL; ออกมาดูก่อนเลยครับ จะได้เช็คได้ง่าย
Date :
2016-12-23 10:09:22
By :
thesin18598
Load balance : Server 04