Page 1 of 1

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

Posted: Tue Feb 17, 2004 12:24 pm
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

Posted: Tue Feb 17, 2004 1:02 pm
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.";
?>

Posted: Tue Feb 17, 2004 1:50 pm
by melindaSA
Thank you it now works!

Posted: Tue Feb 17, 2004 4:07 pm
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