[SOLVED] Why won't this delete record work??

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
melindaSA
Forum Commoner
Posts: 99
Joined: Thu Oct 02, 2003 7:34 am

[SOLVED] Why won't this delete record work??

Post by melindaSA »

I am trying to delete a record from a MySQL database:

Here is my code:

This is where I am calling "delete_app.php?appID=$appID"

Code: Select all

<?php
$query = "SELECT * from application ORDER by appID DESC";

$result = mysql_query($query)
        or die ("could not execute query");

echo "<table>\n";
echo "<tr align="left"><th width="120"><font face="Verdana" size="1"><b>Applicant Name</b></font></th>
      <th width="120"><font face="Verdana" size="1"><b>Position Applied</b></font></th>
      <th width="120"><font face="Verdana" size="1"><b>Application</b></font></th>
      <th width="120"><font face="Verdana" size="1"><b>Date</b></font></th>
      <th width="80"><font face="Verdana" size="1"><b>Resume</b></font></th>
      <th width="80"><font face="Verdana" size="1"><b>Delete</b></font></th></tr>\n";
      

while ( $row = mysql_fetch_array($result))
{
   extract($row);
   echo "<tr>\n";
   echo "<td width="120"><font face="Verdana" size="1">$first_name $last_name</font><br></td>\n";
   echo "<td width="120"><font face="Verdana" size="1">$position_apply</font><br></td>\n";
   echo "<td width="120"><font face="Verdana" size="1"><a href="../show_app.php?appID=$appID" target="_blank">view application</a></font><br></td>\n";
   echo "<td width="120"><font face="Verdana" size="1">$date</font><br></td>\n";

if(file_exists("../resume/".$first_name.$last_name.".doc")){
echo "<td width="80"><font face="Verdana" size="1"><a href="../resume/".$first_name.$last_name.".doc">Yes</a></font><br></td>\n";
} else {

echo "<td width="80"><font face="Verdana" size="1">No</font><br></td>\n";
}
echo "<td width="120"><font face="Verdana" size="1"><a href="delete_app.php?appID=$appID" target="_blank">delete</a></font><br></td>\n";

}
   echo "</tr></table>\n";

?>
This is delete_app.php:

Code: Select all

<?php

 $user="bjrhapdb";
        $host="xxxxxxxx";
        $password="xxxxxxx";
        $database="HRapplication";
        $connection = mysql_pconnect($host, $user, $password)
                or die ("could not connect to server");
        $db = mysql_select_db($database,$connection)
                or die ("could not select database");


   $query = "delete from application
             where appID='$appID'";
   $result = @mysql_query($query);
   if (!$result == TRUE)
   {
   echo 'Application '.$appID.' was deleted.<br />';
   }
    else
   {
   echo 'Application '.$appID.' could not be deleted.<br />';
   }

?>
I get Application 101 could not be deleted.

Where am I going wrong??

Thank you
Last edited by melindaSA on Tue Feb 17, 2004 1:52 pm, edited 2 times in total.
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

Try this:

on delete_app.php, try to echo the var $appID and see if it shows up n is passing correctly... if it does, then try:

Code: Select all

<?php
if(isset($AppID)) {
$del = "DELETE FROM application where appID='$appID'"; 
mysql_query($del) or die (mysql_error());
} else {
echo "file couldnt be deleted.";
?>
melindaSA
Forum Commoner
Posts: 99
Joined: Thu Oct 02, 2003 7:34 am

Post by melindaSA »

Thank you it now works!
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

its nice to have a delete.php

a.) you can send variables of all sorts to it combined with isset() function, you can have a dedicated .php file to delete any type of data from a sql table..

I have a place where a admin can delete users, threads, and other things and i just have for each:

Code: Select all

<?php
if(isset($var of which i'm passing))
//so on n so on
?>
Very handy
Post Reply