0
下面是我用於管理足球賽程和結果管理網站的代碼。我遇到的問題是刪除語法(我認爲我有[ID]混淆)。我有一切工作正常。添加/刪除/編輯PHP/SQL表格
如果我試圖刪除第一行,會顯示以下錯誤:
錯誤刪除[您的SQL語法錯誤;檢查對應於您的MySQL服務器版本使用附近的正確的語法手動「standings_id =‘在行0’」 1]
在SQL表中使用的字段如下:
standings_id, team_name, goals_for, goals_away, goal_difference, points
代碼:
<?
$objConnect =mysql_connect('localhost', 'username', 'password') or die(mysql_error());
$objDB = mysql_select_db("database");
//*** Add Condition ***//
if($_POST["hdnCmd"] == "Add")
{
$strSQL = "INSERT INTO division1_standings_birmingham";
$strSQL .="(standings_id,team_name,goals_for,goals_away,goal_difference,points) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["txtAddstandings_id"]."','".$_POST["txtAddteam_name"]."' ";
$strSQL .=",'".$_POST["txtAddgoals_for"]."' ";
$strSQL .=",'".$_POST["txtAddgoals_away"]."','".$_POST["txtAddgoal_difference"]."' ";
$strSQL .=",'".$_POST["txtAddpoints"]."') ";
$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 division1_standings_birmingham SET ";
$strSQL .="standings_id = '".$_POST["txtEditstandings_id"]."' ";
$strSQL .=",team_name = '".$_POST["txtEditteam_name"]."' ";
$strSQL .=",goals_for = '".$_POST["txtEditgoals_for"]."' ";
$strSQL .=",goals_away = '".$_POST["txtEditgoals_away"]."' ";
$strSQL .=",goal_difference = '".$_POST["txtEditgoal_difference"]."' ";
$strSQL .=",points = '".$_POST["txtEditpoints"]."' ";
$strSQL .="WHERE standings_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 division1_standings_birmingham";
$strSQL .="WHERE standings_id = '".$_GET["standings_id"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Delete [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
$strSQL = "SELECT * FROM division1_standings_birmingham";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?> <br>Welcome, here you can Add/Edit/Delete your records or
<a href="index.php">click here</a> to go back to main page.<br><br>
<form name="frmMain" method="post" action="<?=$_SERVER["PHP_SELF"];?>">
<input type="hidden" name="hdnCmd" value="">
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">standings_id </div></th>
<th width="98"> <div align="center">team_name </div></th>
<th width="198"> <div align="center">goals_for </div></th>
<th width="97"> <div align="center">goals_away </div></th>
<th width="59"> <div align="center">goal_difference </div></th>
<th width="71"> <div align="center">points </div></th>
<th width="30"> <div align="center">Edit </div></th>
<th width="30"> <div align="center">Delete </div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<?
if($objResult["standings_id"] == $_GET["standings_id"] and $_GET["Action"] == "Edit")
{
?>
<tr>
<td><div align="center">
<input type="text" name="txtEditid" size="5" value="<?=$objResult["standings_id"];?>">
<input type="hidden" name="hdnEditid" size="5" value="<?=$objResult["standings_id"];?>">
</div></td>
<td><input type="text" name="txtEditteam_name" size="20" value="<?=$objResult["team_name"];?>"></td>
<td><input type="text" name="txtEditgoals_for" size="20" value="<?=$objResult["goals_for"];?>"></td>
<td><div align="center"><input type="text" name="txtEditgoals_away" size="2" value="<?=$objResult["goals_away"];?>"></div></td>
<td align="right"><input type="text" name="txtEditgoal_difference" size="5" value="<?=$objResult["goal_difference"];?>"></td>
<td align="right"><input type="text" name="txtEditpoints" size="5" value="<?=$objResult["points"];?>"></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["standings_id"];?></div></td>
<td><?=$objResult["team_name"];?></td>
<td><?=$objResult["goals_for"];?></td>
<td><div align="center"><?=$objResult["goals_away"];?></div></td>
<td align="right"><?=$objResult["goal_difference"];?></td>
<td align="right"><?=$objResult["points"];?></td>
<td align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?Action=Edit&standings_id=<?=$objResult["standings_id"];?>">Edit</a></td>
<td align="center"><a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?=$_SERVER["PHP_SELF"];?>?Action=Del&standings_id=<?=$objResult["standings_id"];?>';}">Delete</a></td>
</tr>
<?
}
?>
<?
}
?>
<tr>
<td><div align="center"><input type="text" name="txtAddstandings_id" size="5"></div></td>
<td><input type="text" name="txtAddteam_name" size="20"></td>
<td><input type="text" name="txtAddgoals_for" size="20"></td>
<td><div align="center"><input type="text" name="txtAddgoals_away" size="2"></div></td>
<td align="right"><input type="text" name="txtAddgoal_difference" size="5"></td>
<td align="right"><input type="text" name="txtAddpoints" size="5"></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);
?>
這是如何與SQL PROBL她有嗎?你可以嘗試從你的鏈接中提取相關的部分並將它們發佈在這裏? –
我提供了完整的工作示例,可以替代他的問題。 –