amylou Posted August 14, 2007 Share Posted August 14, 2007 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> Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 14, 2007 Share Posted August 14, 2007 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>"; } ?> Quote Link to comment Share on other sites More sharing options...
amylou Posted August 14, 2007 Author Share Posted August 14, 2007 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 Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 14, 2007 Share Posted August 14, 2007 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. Quote Link to comment Share on other sites More sharing options...
amylou Posted August 14, 2007 Author Share Posted August 14, 2007 it looks as if it refreshes the page but the item that was supposed to be deleted is still there Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 14, 2007 Share Posted August 14, 2007 Well, how about getting rid of the javascript rediect so that we would actually if there was a mysql error? Quote Link to comment Share on other sites More sharing options...
amylou Posted August 14, 2007 Author Share Posted August 14, 2007 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 Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 14, 2007 Share Posted August 14, 2007 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 Quote Link to comment Share on other sites More sharing options...
amylou Posted August 14, 2007 Author Share Posted August 14, 2007 thank you so much that was the problem, i said at the begging that it was going to be something simple and it was Quote Link to comment 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.