Hi guys,

Once again here i am asking for your wise knowledge, i am having porblems with deleting a record.
I can update the record but when i am trying to delete it i cant it it does nothing

here is my code

<?php require_once('Connections/hello.php'); ?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?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;
}
}

$colname_GetName = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_GetName = $_SESSION['MM_Username'];
}
mysql_select_db($database_Web_dbP321, $Web_dbP321);
$query_GetName = sprintf("SELECT user_name FROM users WHERE user_name = %s", GetSQLValueString($colname_GetName, "text"));
$GetName = mysql_query($query_GetName, $Web_dbP321) or die(mysql_error());
$row_GetName = mysql_fetch_assoc($GetName);
$totalRows_GetName = mysql_num_rows($GetName);

$colname_Recordset1 = "-1";
if (isset($_GET['recordID'])) {
  $colname_Recordset1 = $_GET['recordID'];
}
mysql_select_db($database_Web_dbP321, $Web_dbP321);
$query_Recordset1 = sprintf("SELECT news_id, headline FROM news WHERE news_id = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $Web_dbP321) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?><!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>delete record</title>

<link rel="Shortcut Icon" href="images/favicon.ico" />
<style type="text/css">
<!--
.style47 {
	font-weight: bold;
	font-size: 18px;
	color: #999999;
}
.style89 {
	color: #999999;
	font-weight: bold;
}
a:link {
	text-decoration: none;
	color: #333333;
}
a:visited {
	text-decoration: none;
	color: #333333;
}
a:hover {
	text-decoration: none;
	color: #FF6600;
}
a:active {
	text-decoration: none;
	color: #FF0000;
}
body {
	background-repeat: no-repeat;
}
#tdlogin {
	padding: 10px;
}
-->
</style>
<script type="text/javascript">
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }
//-->
</script>
<link href="stylesCCS.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style30 {
	color: #000000;
	font-weight: bold;
	font-size: 18px;
	font-family: Verdana, Arial, Helvetica, sans-serif;
}
.style31 {color: #666666}
.style33 {color: #FF6600}
.style34 {color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; }
.style37 {color: #666666; font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; }
.style38 {color: #FF6600; font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; }
.style39 {
	color: #FF6600;
	font-weight: bold;
}
.style64 {color: #333333}
-->
</style>
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
</head>

<body onload="MM_preloadImages('images/Nav_MenuTop/homeDOWN.gif','images/Nav_MenuTop/homeOVER.gif','images/Nav_MenuTop/productsDOWN.gif','images/Nav_MenuTop/productsOVER.gif','images/Nav_MenuTop/dealersDOWN.gif','images/Nav_MenuTop/dealersOVER.gif','images/Nav_MenuTop/companyDOWN.gif','images/Nav_MenuTop/companyOVER.gif','images/Nav_MenuTop/contactusDOWN.gif','images/Nav_MenuTop/contactusOVER.gif','images/Nav_4Mediums/moto_OVER.gif','images/Nav_4Mediums/atv_OVER.gif','images/Nav_4Mediums/auto_OVER.gif','images/Nav_4Mediums/Bike_OVER.gif','images/Nav_SidebarLeft/sidebar_servicesDOWN.gif','images/Nav_SidebarLeft/sidebar_reviewsDOWN.gif','images/Nav_SidebarLeft/sidebar_newsDOWN.gif','images/Nav_SidebarLeft/sidebar_guidesDOWN.gif');KW_doClock()">
<table width="1051" border="0" align="center" cellpadding="0" cellspacing="0" id="mainlayout">
  <!--DWLayoutTable-->
  <tr>
    <td width="318" height="13"></td>
    <td width="762"></td>
  </tr>
  <tr>
    <td height="106" colspan="2" align="center" valign="middle"><img src="images/toplogo.gif" alt="logo_top" width="1051" height="106" /></td>
  </tr>
  <tr>
    <td height="9"></td>
    <td></td>
  </tr>
  <tr>
    <td height="19" valign="top" nowrap="nowrap" id="tdtext"><script language='JavaScript'>
// Kaosweaver Live Clock Start
function class_clock(f,s,c,b,w,h,d,m,g,z) { // Copyright 2002 by Kaosweaver, All rights reserved
	this.b=b;this.w=w;this.h=h;this.d=d;this.g=g;this.z=z
	this.o='<font style="color:'+c+'; font-family:'+f+'; font-size:'+s+'pt;">';
if (m==1) this.o+=doDate("W0","%20/%20","M0","%20/%20","Y1","%20/%20");

}
var clock=new class_clock("Verdana, Arial, Helvetica, sans-serif","12","#666666","#000000","287",1,1,1,0,0)
// If the clock's size needs adjusting, change the 287 above.
d=document
if (d.all || d.getElementById) {d.write('<span id="activeClock" style="width:'+clock.w+'px; "></span>'); }
else if (d.layers) {d.write('<ilayer  id="wrapClock"><layer width="'+clock.w+'" id="activeClock"></layer></ilayer>'); }
else {KW_doClock(1);}
function KW_doClock(a) { // Copyright 2003 by Kaosweaver, All rights reserved
	d=document;t=new Date();p="";dClock="";	if (d.layers) d.wrapClock.visibility="show";
	tD=(t.getTimezoneOffset()-(clock.z*60))*clock.g;t.setMinutes(tD+t.getMinutes())
	h=t.getHours();m=t.getMinutes();s=t.getSeconds();if (clock.h)
	 {p=(h>11)?"PM":"AM";h=(h>12)?h-12:h;h=(h==0)?12:h;}if (clock.d)
	 {m=(m<=9)?"0"+m:m; s=(s<=9)?"0"+s:s;} dClock = clock.o+h+':'+m+':'+s+' '+p+'</font>';
	if (a) {d.write(dClock);}if (d.layers) {wc = document.wrapClock;lc = wc.document.activeClock;
		lc.document.write(dClock);lc.document.close();
	} else if (d.all) {	activeClock.innerHTML = dClock;
	} else if (d.getElementById) {d.getElementById("activeClock").innerHTML = dClock;}
	if (!a) setTimeout("KW_doClock()",1000);
}


function doDate(){ // Copyright 2002 by Kaosweaver, All rights reserved.
  var t=new Date(),a=doDate.arguments,str="",i,a1,lang="1";
  var month=new Array('January','Jan', 'February','Feb', 'March','Mar', 'April','Apr', 'May','May', 'June','Jun', 'July','Jul', 'August','Aug', 'September','Sep', 'October','Oct', 'November','Nov', 'December','Dec');
  var tday= new Array('Sunday','Sun','Monday','Mon', 'Tuesday','Tue', 'Wednesday','Wed','Thursday','Thr','Friday','Fri','Saturday','Sat');
  for(i=0;i<a.length;i++) {a1=a[i].charAt(1);switch (a[i].charAt(0)) {
  case "M":if  ((Number(a1)==3) && ((t.getMonth()+1)<10)) str+="0";
  str+=(Number(a1)>1)?t.getMonth()+1:month[t.getMonth()*2+Number(a1)];break;
  case "D": if ((Number(a1)==1) && (t.getDate()<10)) str+="0";str+=t.getDate();break;
  case "Y": str+=(a1=='0')?t.getFullYear():t.getFullYear().toString().substring(2);break;
  case "W":str+=tday[t.getDay()*2+Number(a1)];break; default: str+=unescape(a[i]);}}return str;
}

// Kaosweaver Live Clock End
    </script>
      <!-- KW Live Clock -->      </td>
    <td height="19" align="left" nowrap="nowrap" class="style37"><!--DWLayoutEmptyCell-->&nbsp;</td>
  </tr>
  <tr>
    <td height="22" colspan="2" align="left" valign="middle"><img src="images/Nav_4Mediums/line_divider.gif" alt="line_divider" width="912" height="15" /></td>
  </tr>
  <tr>
    <td height="431" colspan="2" valign="top" id="tdlogin"><span class="style30"> <span class="style33">Control </span><span class="style31">Panel</span></span><br />
        <br />
        <p class="style34">Hello, <span class="style39"><?php echo $row_GetName['user_name']; ?></span> Please remember to log out after you are done with your session.<br />
      <br />
    </p>
    <table width="345" height="135" border="0">
      <tr>
        <td width="351" height="131" align="left" valign="top"><fieldset>
          <legend><span class="style38">Menu</span></legend>
          <ul>
            <li class="style37">Insert or Modify Products</li>
            <li class="style37"><a href="inventory.php">View Inventory</a></li>
            <li class="style37"><a href="insertnews.php">Insert  News</a></li>
            <li class="style37"><a href="view_updatenews.php">View and Update News </a></li>
            <li class="style37"><span class="style37">Modify Update Hot Rides</span><br />
              <br />
            </li>
            <li class="style37"><span class="style37"><a href="logout.php">Log Out</a></span><br />
            </li>
          </ul>
        </fieldset>        </td>
      </tr>
    </table>
    <br />
    <span class="style38"><span class="style64">Current</span> <span class="style64">Record:</span></span>  <span class="style47"><?php echo $row_Recordset1['headline']; ?></span><br />
    <span class="style37"><br />
    </span>
    <form id="form1" name="form1" method="post" action="deletenews.php">
      <span class="style38">You are about to delete the Record: </span> <span class="style89"><?php echo $row_Recordset1['headline']; ?></span><br />
      <br />
      <label>
      <input type="submit" name="Submit" id="submit" value="Delete Record" />
      </label>
      <label>
      <input type="button" name="cancel" id="cancel" value="Cancel" 
      onclick="history.back()"/>
      </label>
      <input name="news_id" type="hidden" id="news_id" value="<?php echo $row_DetailRS1['news_id']; ?>" />
    </form>    </td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result($GetName);

mysql_free_result($Recordset1);
?>

Guys i found the problem here is:

- I was using the server behavior DELETE RECORD in DWcs3
- for the " check if variable is defined" i was using the URL parameter WRONG i had to use Primary key value and it worked

thank you anyway

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.