Delete record PROBLEM!!!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
maceved23
Forum Newbie
Posts: 17
Joined: Sun Jul 13, 2003 11:56 pm

Delete record PROBLEM!!!!

Post by maceved23 »

HI.
I have a problem when I try to delete a recor in my DB, my code is not working, when I hit in "ACEPTAR" which is the button to proced with the delete, nothing happen. In other codes I use this It work?????

NEED HELP!!!!!!!!!!!!!! 8O

My code is:

Code: Select all

<?php

db_connect(); 
viewheader(); 


// separate out your SQL query - it'll make your life much easier in the long 
// run. 
$sql = "SELECT * FROM `$dbtable` WHERE `email1`  = '{$_GET['email_busca']}' LIMIT 1"; 
$res = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>'); 

// be consistent about where you place braces on your statements. 


 if ($action == "suppr")
	{
	$res = "DELETE FROM $dbtable WHERE id = '$id'";
	mysql_query ($res);
	mysql_close($db);
	//session_unregister("username");
	//session_unregister("smartid"); 
	//session_unset(); 
	////session_destroy(); 
	//$expire = 365*24*3600; 
	//setcookie("username","",time()-$expire,"/","");
	//setcookie("smartid","",time()-$expire,"/","");  
	header("location: index.php");
	}	
	
if (mysql_num_rows($res) < 1) { 

echo '<p style="margin: 30 0 10 0;">ESTE CORREO ELECTRÓNICO NO HA SIDO REGISTRADO!!!!</p>'; 
echo '<h4><a href="javascript:history.back()">Regresar</a></h4>'; 

} else { 

   // you need to start the table here if you want it to contain all of the 
   // records, if you put the start in the while loop you'll get one table 
   // and heading per record 


?> 

<h4>ESTOS SON LOS DATOS DEL USUARIO CONSULTADO</h4> 

<!-- be consistent about using either single or double quotes around 
     your HTML 
    use CSS properly - then you won't have to use  tags anymore 
    and delete all your  tags --> 

<!-- your table tags were a bit messy - missing closing tags and 
     strangely nested tables, I've tried to clean it up but I'm not 
    sure how well it worked --> 
<table width="80%" border="0" cellpadding="1" cellspacing="0" class="textfield2"> 
<tr bgcolor="#F6F6F6"> 
   <td valign="top" align="right"> 
      - <a href='menu.php'>REGRESAR</a> -  - <a href='logout.php'>SALIR</a> - 
   </td> 
</tr> 
<tr> 
   <td valign="top"> 
      <table width="100%" border="0" cellspacing="1" cellpadding="3" align="center"> 
      <tr bgcolor="#F1F1F1"> 
         <td valign="top" colspan="5"> </td> 
      </tr> 
      <tr bgcolor="#F6F6F6"> 
         <th style="text-align: left;">Nombre</th> 
         <th style="text-align: left;">Email</th> 
         <th style="text-align: left;">Borrar</th> 
         
      </tr> 
<?php 
   // format your code - use tabs to make it easier to follow. 
   while ($row = mysql_fetch_assoc($res)) { 
?> 
      <!-- where does the $bgColor variable come from? --> 
      <tr bgcolor="<?php echo $bgColor; ?>"> 
         <td valign="top"> 
            <b><?php echo $row['nombre']; ?> <?php echo $row['apellido1']; ?> <?php echo $row['apellido2']; ?></b> 
         </td> 
         <td valign="top"> 
            <a href="mailto:<?php echo $row['email1']; ?>"><?php echo $row['email1']; ?></a> 
         </td> 
         <td> 
          
        <input type="hidden" name="action" value="suppr">
		<input type="submit" class="textfield" value="ACEPTAR">
         
         </td> 
         </tr> 
<?php 
    
   } // end while 
    
?> 
      </table> 
   </td> 
</tr> 

</table> 

<?php 
} // end if 
?> 



?>
Thanks for any help.

Mario
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Read the last link in my signature, then report back if that does not apply to you.
I'm thinking that you have a problem not using $_POST (as you use $_GET in the script, that part should work)-
tsg
Forum Contributor
Posts: 142
Joined: Sun Jan 12, 2003 9:22 pm
Location: SE, Alabama
Contact:

Post by tsg »

Something I look for now after someone on another post pointed out ... may save a lot of time and trouble ...
Maybe mysql is trying to tell you something

Code: Select all

<?php
  $res = "DELETE FROM $dbtable WHERE id = '$id'"; 
if(@mysql_query($res)) {
} else {
	echo("Error adding > " . mysql_error() . " < that error");
}

?>
Add the error information to see is mysql outputs an error
Allin1Joe
Forum Newbie
Posts: 4
Joined: Sat Sep 13, 2003 12:17 am
Location: Minneapolis, MN
Contact:

Post by Allin1Joe »

JAM wrote:Read the last link in my signature, then report back if that does not apply to you.
I'm thinking that you have a problem not using $_POST (as you use $_GET in the script, that part should work)-
I would agree with JAM. I put this at the top of all of my modules:

Code: Select all

if (!empty($_GET)) 

&#123; 

  extract($_GET); 

&#125;  

else if (!empty($HTTP_GET_VARS)) 

&#123; 

  extract($HTTP_GET_VARS); 

&#125; 



if (!empty($_POST)) 

&#123;

  extract($_POST);

&#125;  

else if (!empty($HTTP_POST_VARS)) 

&#123;

  extract($HTTP_POST_VARS);

&#125;
maceved23
Forum Newbie
Posts: 17
Joined: Sun Jul 13, 2003 11:56 pm

STILL HAVING THE PROBLEM !!!!!!!!!!!

Post by maceved23 »

Please help me this code become a really problem to me.

My query is working perfect but when I want to delete using the button "ACEPTAR" which have to work for my delete action, nothing happens.

Could someone help me??????

Mario
User avatar
Saethyr
Forum Contributor
Posts: 182
Joined: Thu Sep 25, 2003 9:21 am
Location: Wichita, Kansas USA
Contact:

Post by Saethyr »

Code: Select all

<?php
if ($action == "suppr") 
   { 
   $res = "DELETE FROM $dbtable WHERE id = '$id'"; 
   mysql_query ($res); 
   mysql_close($db); 
   //session_unregister("username"); 
   //session_unregister("smartid"); 
   //session_unset(); 
   ////session_destroy(); 
   //$expire = 365*24*3600; 
   //setcookie("username","",time()-$expire,"/",""); 
   //setcookie("smartid","",time()-$expire,"/","");  
   header("location: index.php"); 
   }   
?>
Your going to need to request those variables man, as far as I can tell it has no clue what the value of $action , $dbtable , or $id are. Since I cannot read spanish I cannot tell what the form values are either. I usually do as follows, if I submit a form with the delete button value == delete and name == report I would say

Code: Select all

<?php
if ($_REQUEST["report"] == 'delete')
      {
          $id = $_REQUEST["id"];
          $dbtable = "MyTable";
   $res = "DELETE FROM $dbtable WHERE id = '$id'"; 
   mysql_query ($res); 
   mysql_close($db); 
   //session_unregister("username"); 
   //session_unregister("smartid"); 
   //session_unset(); 
   ////session_destroy(); 
   //$expire = 365*24*3600; 
   //setcookie("username","",time()-$expire,"/",""); 
   //setcookie("smartid","",time()-$expire,"/","");  
   header("location: index.php"); 
   } 
?>
or something like that. it's very hard for me to do this since I have no idea what the spanish is.
Post Reply