emediastudios Posted October 28, 2007 Share Posted October 28, 2007 I have records in my database that all have a id number that is unique , But if i have the same name on a record and i delete the record from a dreamweaver generated code it deletes all records of the same name. I want to filter my deletion by id so that if i had 10 properties with the same name it would only delete the selected record? Does this make sense. Heres the code i use in my file <?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; } } if ((isset($_POST['id'])) && ($_POST['id'] != "")) { $deleteSQL = sprintf("DELETE FROM employees WHERE id=%s", GetSQLValueString($_POST['id'], "int")); mysql_select_db($database_gcproperty, $gcproperty); $Result1 = mysql_query($deleteSQL, $gcproperty) or die(mysql_error()); $deleteGoTo = "property_deleted.php"; if (isset($_SERVER['QUERY_STRING'])) { $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?"; $deleteGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $deleteGoTo)); } if ((isset($_POST['name'])) && ($_POST['name'] != "")) { $deleteSQL = sprintf("DELETE FROM employees WHERE name=%s", GetSQLValueString($_POST['name'], "text")); mysql_select_db($database_gcproperty, $gcproperty); $Result1 = mysql_query($deleteSQL, $gcproperty) or die(mysql_error()); $deleteGoTo = "property_deleted.php"; if (isset($_SERVER['QUERY_STRING'])) { $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?"; $deleteGoTo .= $_SERVER['QUERY_STRING']; $myFile = array(); for($i=1;$i<=9;$i++) { $myFile[$i] = "../images/" . $_POST['photo' . $i]; if (!empty($_POST['photo'.$i])) unlink($myFile[$i]); } } header("Location: $deleteGoTo"); } mysql_select_db($database_gcproperty, $gcproperty); $query_Recordset1 = "SELECT * FROM employees ORDER BY id ASC"; $Recordset1 = mysql_query($query_Recordset1, $gcproperty) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> Quote Link to comment https://forums.phpfreaks.com/topic/75079-solved-delete-record/ Share on other sites More sharing options...
emediastudios Posted October 28, 2007 Author Share Posted October 28, 2007 I got it to work But this code looks wrong there are duplicate codes <?php if ((isset($_POST['id'])) && ($_POST['id'] != "")) { $deleteSQL = sprintf("DELETE FROM employees WHERE id=%s", GetSQLValueString($_POST['id'], "int")); mysql_select_db($database_gcproperty, $gcproperty); $Result1 = mysql_query($deleteSQL, $gcproperty) or die(mysql_error()); $deleteGoTo = "property_deleted.php"; if (isset($_SERVER['QUERY_STRING'])) { $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?"; $deleteGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $deleteGoTo)); } if ((isset($_POST['id'])) && ($_POST['id'] != "")) { $deleteSQL = sprintf("DELETE FROM employees WHERE id=%s", GetSQLValueString($_POST['id'], "int")); mysql_select_db($database_gcproperty, $gcproperty); $Result1 = mysql_query($deleteSQL, $gcproperty) or die(mysql_error()); $deleteGoTo = "property_deleted.php"; if (isset($_SERVER['QUERY_STRING'])) { $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?"; $deleteGoTo .= $_SERVER['QUERY_STRING']; $myFile = array(); for($i=1;$i<=9;$i++) { $myFile[$i] = "../images/" . $_POST['photo' . $i]; if (!empty($_POST['photo'.$i])) unlink($myFile[$i]); } } header("Location: $deleteGoTo"); } mysql_select_db($database_gcproperty, $gcproperty); $query_Recordset1 = "SELECT * FROM employees ORDER BY id ASC"; $Recordset1 = mysql_query($query_Recordset1, $gcproperty) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> I deleted the duplicated code but i get errors. Quote Link to comment https://forums.phpfreaks.com/topic/75079-solved-delete-record/#findComment-379713 Share on other sites More sharing options...
fenway Posted October 29, 2007 Share Posted October 29, 2007 Huh? Quote Link to comment https://forums.phpfreaks.com/topic/75079-solved-delete-record/#findComment-380369 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.