emediastudios Posted November 5, 2007 Share Posted November 5, 2007 Im some having trouble with deleting a record, surely it isnt that hard, dont know what im doing wrong. this is the error i am gettin 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 '` WHERE id=1' at line 1 Here is my delete code <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $currentPage = $_SERVER["PHP_SELF"]; if ((isset($_POST['id'])) && ($_POST['id'] != "")) { $deleteSQL = sprintf("DELETE FROM ``application`` WHERE id=%s", GetSQLValueString($_POST['id'], "int")); mysql_select_db($database_p2w, $p2w); $Result1 = mysql_query($deleteSQL, $p2w) or die(mysql_error()); $deleteGoTo = "application_deleted.php"; if (isset($_SERVER['QUERY_STRING'])) { $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?"; $deleteGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $deleteGoTo)); } $maxRows_Recordset1 = 2; $pageNum_Recordset1 = 0; if (isset($_GET['pageNum_Recordset1'])) { $pageNum_Recordset1 = $_GET['pageNum_Recordset1']; } $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1; mysql_select_db($database_p2w, $p2w); $query_Recordset1 = "SELECT * FROM `application`"; $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1); $Recordset1 = mysql_query($query_limit_Recordset1, $p2w) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); if (isset($_GET['totalRows_Recordset1'])) { $totalRows_Recordset1 = $_GET['totalRows_Recordset1']; } else { $all_Recordset1 = mysql_query($query_Recordset1); $totalRows_Recordset1 = mysql_num_rows($all_Recordset1); } $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1; $queryString_Recordset1 = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_Recordset1") == false && stristr($param, "totalRows_Recordset1") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams)); } } $queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1); ?> I have a record in my database with a incrementing primary key called id. and a hidden field in the form with id posted within it. Thanks for any help Link to comment https://forums.phpfreaks.com/topic/76047-solved-delete-record/ Share on other sites More sharing options...
kks_krishna Posted November 5, 2007 Share Posted November 5, 2007 I think your query is missing single quote. try this : DELETE FROM ``application`` WHERE id='%s'" Link to comment https://forums.phpfreaks.com/topic/76047-solved-delete-record/#findComment-384954 Share on other sites More sharing options...
emediastudios Posted November 5, 2007 Author Share Posted November 5, 2007 thanks, i changed it and it gave me this error 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 '` WHERE id='1'' at line 1 thats with your code, ??? and when i have no (') i get what i had first? Weird Link to comment https://forums.phpfreaks.com/topic/76047-solved-delete-record/#findComment-384977 Share on other sites More sharing options...
rajivgonsalves Posted November 5, 2007 Share Posted November 5, 2007 I think ``application`` should be `application` Link to comment https://forums.phpfreaks.com/topic/76047-solved-delete-record/#findComment-384981 Share on other sites More sharing options...
emediastudios Posted November 5, 2007 Author Share Posted November 5, 2007 I think ``application`` should be `application` u da man, wizzkid, your name says it all dreamweaver, generated that code. Link to comment https://forums.phpfreaks.com/topic/76047-solved-delete-record/#findComment-384989 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.