Jump to content

Recommended Posts

the following code works but it will not delete the item when the delete link is clicked. probably something simple but have been looking at this to long

thanks for help

 


<?PHP

include 'config.php';// this has my database connection stuff
if($_Post['m'] == 'del' )
{
   $query ="DELETE  FROM timeoff WHERE requestId = '$requestId'";
   mysql_query($query) or die(mysql_error());
    echo "<script language=\"javascript\"> 
   		location.href=index.php</script>";
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>index page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<table width="75%" border="1">
  <tr> 
    <td>Request Id</td>
    <td>First</td>
<td>Last</td>
<td>Requested Date Off</td>
    <td>OPTIONS</td>
  </tr>
<?PHP
$requestId = intval ( $_Post['requestId'] );
  $query = "SELECT * FROM timeoff ORDER BY requestedDate ASC";
  $_rs = mysql_query($query ) or die(mysql_error());
  if( $_rs )
  {
     while ( $_rw = mysql_fetch_object ($_rs ) ) 
     {
$_html ="<tr> 
    <td>$_rw->requestId</td>
    <td>$_rw->first</td>
<td>$_rw->last</td>
<td>$_rw->requestedDate</td>
     <td>
   <a href=\"index.php?id=$_rw->id&m=del\">DELETE </a></td>
    </tr>";
echo $_html;
     }
  }
else
{
  
}
?>
   <tr> 
     <td> </td>
     <td> </td>
     <td> </td>
   </tr>
   <tr> 
     <td> </td>
     <td> </td>
     <td></td>
   </tr>
   <tr>
     <td> </td>
     <td> </td>
     <td> </td>
   </tr>
</table>
</body>
</html>




Link to comment
https://forums.phpfreaks.com/topic/64916-solved-why-wont-this-delete/
Share on other sites

Firstly, the data is in the GET array, not the POST array. Second, you dont define $requestId. Try:

 

<?php

include 'config.php';// this has my database connection stuff
if($_GET['m'] == 'del' )
{
$requestId = $_GET['id'];
   $query ="DELETE  FROM timeoff WHERE requestId = '$requestId'";
   mysql_query($query) or die(mysql_error());
    echo "<script language=\"javascript\"> 
   		location.href=index.php</script>";
}
?>

i tried that and it still does not work, when i click on it looks like refreshes page and then i get done but with errors on the bottom of screen

 

'done but with errors on the bottom of the screen' sounds very much like a javascript error notice displayed in the browser status window and nothing to do with any php problem.  Would you care to clarify exactly what you mean, especially by "still does not work" because I'd have given you the same initial corrected code as GingerRobot.  Obviously, there's more going on than we know.

i got rid of the java script and there is no mysql error this is what the out put looks like and when the delete link is hit nothing happens this is shown in the browser in a table format

 

 

 

 

434 tammy saucier 2007-10-29 DELETE 

435 tammy saucier 2007-10-30 DELETE 

521 hello goodbye 2007-12-01 DELETE 

522 goodbye hello 2007-12-01 DELETE 

523 fgjdkj djdfjfgj 2007-12-01 DELETE 

     

   

     

 

I suppose it would help if you were actually putting the right variable into your url string wouldn't it?

 

Try:

<a href=\"index.php?id=$_rw->requestId&m=del\">DELETE </a></td>

 

Call me old fashioned but i thought you might have noticed a blank in the URL :P

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.