ดู CODE ให้หน่อยครับ update กับ INSERT ไม่ได้ครับ ช่วนที่คับพี่น้องครับ
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 = 'QQ' ,date = '23' ,date2 = 'Feb' ,date3 = '2010' ,time = '16' ,time2 = '' at line 1]
INSERT
Error Save [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 ''40','wwww','www','22','Jan','2010','8','00','wwwwwwww','')' at line 1]
Code (VB.NET)
<html>
<head>
<title></title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","999999") or die ("Error Connect to Database");
$objDB = mysql_select_db("online");
//*** Add Condition ***//
if($_POST["hdnCmd"] == "Add")
{
$strSQL = "INSERT INTO form ";
$strSQL .="('".$_POST["txtAddid"]."','".$_POST["txtAddname"]."','".$_POST["txtAddgroup"]."','".$_POST["txtAdddate"]."','".$_POST["txtAdddate2"]."','".$_POST["txtAdddate3"]."','".$_POST["txtAddtime"]."','".$_POST["txtAddtime2"]."','".$_POST["txtAdddetails"]."','".$_POST["txtAddstatus"]."') ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Save [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
//*** Update Condition ***//
if($_POST["hdnCmd"] == "Update")
{
$strSQL = "UPDATE form SET ";
$strSQL .="id = '".$_POST["txtEditid"]."' ";
$strSQL .=",name = '".$_POST["txtEditname"]."' ";
$strSQL .=",group = '".$_POST["txtEditgroup"]."' ";
$strSQL .=",date = '".$_POST["txtEditdate"]."' ";
$strSQL .=",date2 = '".$_POST["txtEditdate2"]."' ";
$strSQL .=",date3 = '".$_POST["txtEditdate3"]."' ";
$strSQL .=",time = '".$_POST["txtEdittime"]."' ";
$strSQL .=",time2 = '".$_POST["txtEdittime2"]."' ";
$strSQL .=",details = '".$_POST["txtEditdetails"]."' ";
$strSQL .=",status = '".$_POST["txtEditstatus"]."' ";
$strSQL .="WHERE id = '".$_POST["hdnEditid"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Update [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
//*** Delete Condition ***//
if($_GET["Action"] == "Del")
{
$strSQL = "DELETE FROM form ";
$strSQL .="WHERE id = '".$_GET["CusID"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Delete [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
$strSQL = "SELECT * FROM form";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<form name="frmMain" method="post" action="<?=$_SERVER["PHP_SELF"];?>">
<input type="hidden" name="hdnCmd" value="">
<table width="1207" border="1">
<tr>
<th width="47"> <div align="center">ID </div></th>
<th width="123"> <div align="center">Name </div></th>
<th width="90"> <div align="center">Group</div></th>
<th width="263"> <div align="center">Date</div></th>
<th width="156"> <div align="center">Time</div></th>
<th width="241"><div align="center">Details</div></th>
<th width="135"> <div align="center">Status</div></th>
<th width="42"> <div align="center">Edit </div></th>
<th width="52"> <div align="center">Delete </div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<?
if($objResult["id"] == $_GET["CusID"] and $_GET["Action"] == "Edit")
{
?>
<tr>
<td>
<div align="center">
<input name="txtEditid" type="text" id="txtEditid" value="<?=$objResult["id"];?>" size="5">
<input name="hdnEditid" type="hidden" id="hdnEditid" value="<?=$objResult["id"];?>" size="5">
</div></td>
<td><div align="center">
<input name="txtEditname" type="text" id="txtEditname" value="<?=$objResult["name"];?>" size="20">
</div></td>
<td><div align="center">
<input name="txtEditgroup" type="text" id="txtEditgroup" value="<?=$objResult["group"];?>" size="15">
</div></td>
<td><div align="center">
<input name="txtEditdate" type="text" id="txtEditdate" value="<?=$objResult["date"];?>" size="2">
:
<input name="txtEditdate2" type="text" id="txtEditdate2" value="<?=$objResult["date2"];?>" size="2">
:
<input name="txtEditdate3" type="text" id="txtEditdate3" value="<?=$objResult["date3"];?>" size="5">
</div></td>
<td align="right"><div align="center">
<input name="txtEdittime" type="text" id="txtEdittime" value="<?=$objResult["time"];?>" size="5">
:
<input name="txtEdittime2" type="text" id="txtEdittime2" value="<?=$objResult["time2"];?>" size="5">
</div></td>
<td align="right"><div align="center">
<input name="txtEditdetails" type="text" id="txtEditdetails" value="<?=$objResult["details"];?>" size="40">
</div></td>
<td align="right"><div align="center">
<input name="txtEditstatus " type="text" id="txtEditstatus " value="<?=$objResult["status"];?>" size="15">
</div></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='<?=$_SERVER["PHP_SELF"];?>';">
</div></td>
</tr>
<?
}
else
{
?>
<tr>
<td>
<div align="center">
<?=$objResult["id"];?>
</div></td>
<td>
<div align="center">
<?=$objResult["name"];?>
</div></td>
<td>
<div align="center">
<?=$objResult["group"];?>
</div></td>
<td><div align="center"><strong>
<?=$objResult["date"];?>
:
<?=$objResult["date2"];?>
:
<?=$objResult["date3"];?>
</strong></div></td>
<td align="right">
<div align="center">
<?=$objResult["time"];?>
:
<?=$objResult["time2"];?>
</div></td>
<td align="right">
<div align="center">
<?=$objResult["details"];?>
</div></td>
<td align="right">
<div align="center">
<?=$objResult["status"];?>
</div></td>
<td align="center"><div align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?Action=Edit&CusID=<?=$objResult["id"];?>">Edit</a></div></td>
<td align="center"><div align="center"><a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?=$_SERVER["PHP_SELF"];?>?Action=Del&CusID=<?=$objResult["id"];?>';}">Delete</a></div></td>
</tr>
<?
}
?>
<?
}
?>
<tr>
<td>
<div align="center">
<input type="text" name="txtAddid" size="5" id="txtAddid">
</div></td>
<td>
<div align="center">
<input type="text" name="txtAddname" size="20" id="txtAddname">
</div></td>
<td>
<div align="center">
<input type="text" name="txtAddgroup" size="15" id="txtAddgroup">
</div></td>
<td>
<div align="center">
<input type="text" name="txtAdddate" size="2" id="txtAdddate">
:
<input type="text" name="txtAdddate2" size="2" id="txtAdddate2">
:
<input type="text" name="txtAdddate3" size="5" id="txtAdddate3">
</div></td>
<td align="right">
<div align="center">
<input type="text" name="txtAddtime" size="5" id="txtAddtime">
:
<input type="text" name="txtAddtime2" size="5" id="txtAddtime2">
</div></td>
<td align="right">
<div align="center">
<input type="text" name="txtAdddetails" size="40" id="txtAdddetails">
</div></td>
<td align="right">
<div align="center">
<input type="text" name="txtAddstatus " size="15" id="txtAddstatus ">
</div></td>
<td colspan="2" align="right">
<div align="center">
<input name="btnAdd" type="button" id="btnAdd" value="Add" OnClick="frmMain.hdnCmd.value='Add';frmMain.submit();">
</div></td>
</tr>
</table>
</form>
<?
mysql_close($objConnect);
?>
</body>
</html>
Tag : - - - -
Date :
2010-01-22 08:40:38
By :
care123
View :
989
Reply :
3
ขอบคุณ ครับพี่น้องครับ
group เปลียนชื่อแล้วครับ
UPDATE form SET
ยังไม่ได้ครับ
Code (VB.NET)
<html>
<head>
<title></title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","999999") or die ("Error Connect to Database");
$objDB = mysql_select_db("online");
//*** Add Condition ***//
if($_POST["hdnCmd"] == "Add")
{
$strSQL = "INSERT INTO form tabel(id,name,name2,date,date2,date3,time,time2,details,status)";
//$strSQL .="(CustomerID,Name,Email,CountryCode,Budget,Used) ";
//$strSQL .="VALUES ";
//$strSQL .="('".$_POST["txtAddCustomerID"]."','".$_POST["txtAddName"]."','".$_POST["txtAddEmail"]."' ";
//$strSQL .=",'".$_POST["txtAddCountryCode"]."','".$_POST["txtAddBudget"]."','".$_POST["txtAddUsed"]."') ";
//$objQuery = mysql_query($strSQL);
$strSQL .=" VALUES ('".$_POST["txtAddid"]."','".$_POST["txtAddname"]."','".$_POST["txtAddname2"]."','".$_POST["txtAdddate"]."','".$_POST["txtAdddate2"]."','".$_POST["txtAdddate3"]."','".$_POST["txtAddtime"]."','".$_POST["txtAddtime2"]."','".$_POST["txtAdddetails"]."','".$_POST["txtAddstatus"]."') ";
//$strSQL .=",'".$_POST["txtAdddate"]."','".$_POST["txtAdddate2"]."','".$_POST["txtAdddate3"]."' ";
//$strSQL .=",'".$_POST["txtAddtime"]."','".$_POST["txtAddtime2"]."','".$_POST["txtAdddetails"]."','".$_POST["txtAddstatus"]."') ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Save [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
//*** Update Condition ***//
if($_POST["hdnCmd"] == "Update")
{
//$strSQL = "UPDATE customer SET ";
//$strSQL .="CustomerID = '".$_POST["txtEditCustomerID"]."' ";
//$strSQL .=",Name = '".$_POST["txtEditName"]."' ";
//$strSQL .=",Email = '".$_POST["txtEditEmail"]."' ";
//$strSQL .=",CountryCode = '".$_POST["txtEditCountryCode"]."' ";
//$strSQL .=",Budget = '".$_POST["txtEditBudget"]."' ";
//$strSQL .=",Used = '".$_POST["txtEditUsed"]."' ";
//$strSQL .="WHERE CustomerID = '".$_POST["hdnEditCustomerID"]."' ";
//$objQuery = mysql_query($strSQL);
// $strSQL = "UPDATE form SET";
$strSQL = "UPDATE form SET ";
$strSQL .="id = '".$_POST["txtEditid"]."' ";
$strSQL .=",name = '".$_POST["txtEditname"]."' ";
$strSQL .=",name2 = '".$_POST["txtEditname2"]."' ";
$strSQL .=",date = '".$_POST["txtEditdate"]."' ";
$strSQL .=",date2 = '".$_POST["txtEditdate2"]."' ";
$strSQL .=",date3 = '".$_POST["txtEditdate3"]."' ";
$strSQL .=",time = '".$_POST["txtEdittime"]."' ";
$strSQL .=",time2 = '".$_POST["txtEdittime2"]."' ";
$strSQL .=",details = '".$_POST["txtEditdetails"]."' ";
$strSQL .=",status = '".$_POST["txtEditstatus"]."' ";
$strSQL .="WHERE id = '".$_POST["hdnEditid"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Update [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
//*** Delete Condition ***//
if($_GET["Action"] == "Del")
{
$strSQL = "DELETE FROM form ";
$strSQL .="WHERE id = '".$_GET["CusID"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Delete [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
$strSQL = "SELECT * FROM form";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<form name="frmMain" method="post" action="<?=$_SERVER["PHP_SELF"];?>">
<input type="hidden" name="hdnCmd" value="">
</form>
<?
mysql_close($objConnect);
?>
<table width="1207" border="1">
<tr>
<th width="47"> <div align="center">ID </div></th>
<th width="123"> <div align="center">Name </div></th>
<th width="90"> <div align="center">Group</div></th>
<th width="263"> <div align="center">Date</div></th>
<th width="156"> <div align="center">Time</div></th>
<th width="241"><div align="center">Details</div></th>
<th width="135"> <div align="center">Status</div></th>
<th width="42"> <div align="center">Edit </div></th>
<th width="52"> <div align="center">Delete </div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<?
if($objResult["id"] == $_GET["CusID"] and $_GET["Action"] == "Edit")
{
?>
<tr>
<td><div align="center">
<input name="txtEditid" type="text" id="txtEditid" value="<?=$objResult["id"];?>" size="5">
<input name="hdnEditid" type="hidden" id="hdnEditid" value="<?=$objResult["id"];?>" size="5">
</div></td>
<td><div align="center">
<input name="txtEditname" type="text" id="txtEditname" value="<?=$objResult["name"];?>" size="20">
</div></td>
<td><div align="center">
<input name="txtEditgroup" type="text" id="txtEditgroup" value="<?=$objResult["name2"];?>" size="15">
</div></td>
<td><div align="center">
<input name="txtEditdate" type="text" id="txtEditdate" value="<?=$objResult["date"];?>" size="2">
:
<input name="txtEditdate2" type="text" id="txtEditdate2" value="<?=$objResult["date2"];?>" size="2">
:
<input name="txtEditdate3" type="text" id="txtEditdate3" value="<?=$objResult["date3"];?>" size="5">
</div></td>
<td align="right"><div align="center">
<input name="txtEdittime" type="text" id="txtEdittime" value="<?=$objResult["time"];?>" size="5">
:
<input name="txtEdittime2" type="text" id="txtEdittime2" value="<?=$objResult["time2"];?>" size="5">
</div></td>
<td align="right"><div align="center">
<p>
<input name="txtEditdetails" type="text" id="txtEditdetails" value="<?=$objResult["details"];?>" size="40">
</p>
</div></td>
<td align="right"><div align="center">
<input name="txtEditstatus " type="text" id="txtEditstatus " value="<?=$objResult["status"];?>" size="15">
</div></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='<?=$_SERVER["PHP_SELF"];?>';">
</div></td>
</tr>
<?
}
else
{
?>
<tr>
<td><div align="center">
<?=$objResult["id"];?>
</div></td>
<td><div align="center">
<?=$objResult["name"];?>
</div></td>
<td><div align="center">
<?=$objResult["name2"];?>
</div></td>
<td><div align="center"><strong>
<?=$objResult["date"];?>
:
<?=$objResult["date2"];?>
:
<?=$objResult["date3"];?>
</strong></div></td>
<td align="right"><div align="center">
<?=$objResult["time"];?>
:
<?=$objResult["time2"];?>
</div></td>
<td align="right"><div align="center">
<?=$objResult["details"];?>
</div></td>
<td align="right"><div align="center">
<?=$objResult["status"];?>
</div></td>
<td align="center"><div align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?Action=Edit&CusID=<?=$objResult["id"];?>">Edit</a></div></td>
<td align="center"><div align="center"><a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?=$_SERVER["PHP_SELF"];?>?Action=Del&CusID=<?=$objResult["id"];?>';}">Delete</a></div></td>
</tr>
<?
}
?>
<?
}
?>
<tr>
<td><div align="center">
<input type="text" name="txtAddid" size="5" id="txtAddid">
</div></td>
<td><div align="center">
<input type="text" name="txtAddname" size="20" id="txtAddname">
</div></td>
<td><div align="center">
<input type="text" name="txtAddnane2" size="15" id="txtAddnane2">
</div></td>
<td><div align="center">
<input type="text" name="txtAdddate" size="2" id="txtAdddate">
:
<input type="text" name="txtAdddate2" size="2" id="txtAdddate2">
:
<input type="text" name="txtAdddate3" size="5" id="txtAdddate3">
</div></td>
<td align="right"><div align="center">
<input type="text" name="txtAddtime" size="5" id="txtAddtime">
:
<input type="text" name="txtAddtime2" size="5" id="txtAddtime2">
</div></td>
<td align="right"><div align="center">
<input type="text" name="txtAdddetails" size="40" id="txtAdddetails">
</div></td>
<td align="right"><div align="center">
<input type="text" name="txtAddstatus " size="15" id="txtAddstatus ">
</div></td>
<td colspan="2" align="right"><div align="center">
<input name="btnAdd" type="button" id="btnAdd" value="Add" onClick="frmMain.hdnCmd.value='Add';frmMain.submit();">
</div></td>
</tr>
</table>
</body>
</html>
Date :
2010-01-22 10:44:57
By :
care123
Load balance : Server 04