Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 135,912 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,563 people online right now. Registration is fast and FREE... Join Now!




Delete a mySQL record

 
Reply to this topicStart new topic

Delete a mySQL record

morcomm
22 May, 2008 - 10:46 PM
Post #1

New D.I.C Head
*

Joined: 27 Mar, 2008
Posts: 49


My Contributions
Hi,

I have been battling with this for a while now. I have created a master detail page to display all records in a table. From here I have added an insert option that inserts records properly. I used Dreamweaver CS3 to generate all the code for the master detail page. The problem that I am having is with the deleting of records. I let DW generate the del logic page, that redirects to the master page after it is done. When I run the link "delete.php?recordID=<?php echo $row_table['id']; ?>" it just sits on the logic page doing nothing.

The Code for the logic page is as follows:

CODE
<?php require_once('../Connections/Main.php'); ?>
<?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($_GET['table'])) && ($_GET['table'] != "")) {
  $deleteSQL = sprintf("DELETE FROM news WHERE id=%s",
                       GetSQLValueString($_GET['table'], "text"));

  mysql_select_db($database_Main, $Main);
  $Result1 = mysql_query($deleteSQL, $Main) or die(mysql_error());

  $deleteGoTo = "index.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
    $deleteGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $deleteGoTo));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>


User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Delete A MySQL Record
23 May, 2008 - 12:06 AM
Post #2

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,433



Thanked: 64 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
You are checking for the existence of $_GET['table'], yet you are passing in recordID=<?php echo $row_table['id']; ?>... so I don't see in your code where you reference the value that you are sending in.

Maybe you want to check for $_GET['recordID'] ?
User is offlineProfile CardPM
+Quote Post

morcomm
RE: Delete A MySQL Record
23 May, 2008 - 12:36 AM
Post #3

New D.I.C Head
*

Joined: 27 Mar, 2008
Posts: 49


My Contributions
QUOTE(no2pencil @ 23 May, 2008 - 01:06 AM) *

You are checking for the existence of $_GET['table'], yet you are passing in recordID=<?php echo $row_table['id']; ?>... so I don't see in your code where you reference the value that you are sending in.

Maybe you want to check for $_GET['recordID'] ?


Thanks, that worked.
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Delete A MySQL Record
23 May, 2008 - 12:39 AM
Post #4

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,433



Thanked: 64 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
Good deal! biggrin.gif icon_up.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 07:46AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month