Jump to content

[SOLVED] Cannot Delete From DB


steviemac

Recommended Posts

I am very new to PHP/MYSQL  I have an on line registration.  I want users to be able to cancel a course.  They do it by inputting their email address which will search the DB. Then selecting the course using  a radio button to delete it.  I will then get an e-mail stating they have canceled and they get a conformation e-mail. 

I have everything working but the delete from the DB

///////////////////////////The code to Search  and Form produced to delete

<form name="search" method="post" action="<?=$PHP_SELF?>">
Enter  E-Mail Address: <input type="text" name="find" /> 
<input type="hidden" NAME="field" VALUE="email_address">



<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
  
</form>


<?php
//This is only displayed if they have submitted the form
if ($searching =="yes")
{
echo "<h2>Results</h2><p>";

//If they did not enter a search term we give them an error
if ($find == "")
{
echo "<p>You forgot to enter a search term";
exit;
}

// Otherwise we connect to our Database
mysql_connect("localhost", "**", "**") or die(mysql_error());
mysql_select_db("DB Name") or die(mysql_error());

// We preform a bit of filtering
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);

//Now we search for our search term, in the field the user specified
$data = mysql_query("SELECT * FROM table WHERE upper($field) LIKE'%$find%'");

//And we display the results

while($result = mysql_fetch_array( $data ))
{
echo "<form action='delete_course.php' name='delete' method ='POST' >";
echo "<table width='700' cellspacing'0' cellpadding='0' border='0'><tr>";
echo "<td class='thetag' bgcolor='#DDDDDD'>Delete</td>";
echo "<td class='thetag' bgcolor='#DDDDDD'>ID";
echo "<td class='thetag' bgcolor='#DDDDDD'>Course";
echo "<td class='thetag' bgcolor='#DDDDDD'>Contact Person";
echo "<td class='thetag' bgcolor='#DDDDDD'>Agency</td>";
echo "<td class='thetag' bgcolor='#DDDDDD'>email_address</td>";
echo "<td class='thetag' bgcolor='#DDDDDD'>Student_2_Name</td></tr>";
echo "<tr><td class='thevalue'><input type=\"radio\" name=\"delete\" value=\"$result[id]\" /></td>";
echo  "<td class='thevalue'><input type=\"text\" size=\"3\" name=\"id\" value=\"$result[id]\" /></td>";
echo  "<td class='thevalue'><input type=\"text\" size=\"25\" name=\"Course\" value=\"$result[Course]\" /></td>";
echo "<td class='thevalue'><input type=\"text\" size=\"30\" name=\"Contact_Person\" value=\"$result[Contact_Person]\" /></td>";
echo "<td class='thevalue'><input type=\"text\" size=\"30\" name=\"Agency\" value=\"$result[Agency]\" /></td>";
echo "<td class='thevalue'><input type=\"text\" size=\"30\" name=\"email_address\" value=\"$result[email_address]\" /></td>";
echo "<td class='thevalue'><input type=\"text\" size=\"30\" name=\"StudentName\" value=\"$result[student_2_Name]\" /></td>";
echo "</td></tr>";

}
echo "<tr><td colspan=\"5\"><input type=\"submit\" name=\"submit\" value=\"Delete Selected\" /></td></tr></table>\n";
echo "</form>\n";
//This counts the number or results - and if there wasn't any it gives them a little message explaining that
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}

//And we remind them what they searched for
echo "<b>Searched For:</b> " .$find;
}
?>

 

////////////////////////////////This is the delete_course.php code

<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('track_errors', true);
//Connect to DB
$db = mysql_connect("localhost", "**, "**");
mysql_select_db("DB Name");
if($_POST['delete']) {


    $result = mysql_query("DELETE FROM table WHERE id, = '".$_POST['delete']."'");

    echo "You deleted the following course information:";
echo "<br>";
echo "ID Number:".$_POST['delete'];
echo "<br>";
echo "Course Name: " .$_POST['Course'];
echo "<br>";
echo "Contact Person: ".$_POST['Contact_Person'];
echo "<br>";
echo "Agency: ".$_POST['Agency'];
echo "<br>";
echo "Agency E-Mail: ".$_POST['email_address'];
echo "<br>";
echo "Name of Student 2: ".$_POST['Student_2_Name'];
} else {
    echo 'You didnt enter any data';
}
?> 
/////////////////////////////E-Mail Code This works fine
<?php
function DoStripSlashes($FieldValue) 
{ 
if ( get_magic_quotes_gpc() ) { 
  if (is_array($FieldValue) ) { 
   return array_map('DoStripSlashes', $FieldValue); 
  } else { 
   return stripslashes($FieldValue); 
  } 
} else { 
  return $FieldValue; 
} 
}

#----------
# FilterCChars:

function FilterCChars($TheString)
{
return preg_replace('/[\x00-\x1F]/', '', $TheString);
}


if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ClientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ClientIP = $_SERVER['REMOTE_ADDR'];
}
$FTGSeats = DoStripSlashes( $_POST['Course'] );
$FTGSeats = DoStripSlashes( $_POST['id'] );
$FTGStudent_2_Name = DoStripSlashes( $_POST['Student_2_Name'] );
$FTGSSN_Student_2 = DoStripSlashes( $_POST['SSN_Student_2'] );
$FTGAgency = DoStripSlashes( $_POST['Agency'] );
$FTGContact_Person = DoStripSlashes( $_POST['Contact_Person'] );
$FTGemail_address = DoStripSlashes( $_POST['email_address'] );

# Email to Form Owner

$emailSubject = FilterCChars("Cancel Course $FTGCourse");

$emailBody = "$FTGContact_Person of the $FTGAgency has canceled for the following course:\n"
. "$FTGCourse.\n"
. "\n"
. "They have submitted the following information.\n"
. "\n"
. "Course ID: $FTGid\n"
. "\n"
. "Student 2 Name: $FTGStudent_2_Name\n"
. "\n"
. "Agency: $FTGAgency\n"
. "\n"
. "Contact Person: $FTGContact_Person\n"
. "\n"
. "email address: $FTGemail_address\n"
. "\n"
. "";
$emailTo = "Steve MacLasco <mac428@nycap.rr.com>";
  
$emailFrom = FilterCChars("$FTGemail_address");
  
$emailHeader = "From: $emailFrom\n"
  . "Bcc: Steve MacLasco <mac428@nycap.rr.com>" . "\n"
  . "MIME-Version: 1.0\n"
  . "Content-type: text/plain; charset=\"ISO-8859-1\"\n"
  . "Content-transfer-encoding: 8bit\n";
  
mail($emailTo, $emailSubject, $emailBody, $emailHeader);
# Confirmation Email to User

$confEmailTo = FilterCChars($FTGemail_address);

$confEmailSubject = FilterCChars("Zone 5 Academy FTGCourse Registration");

$confEmailBody = "You have deleted the sniper course. \n"
. "You have submitted the following information:\n"
. "\n"
. "\n"
. "Course ID number: $FTGid\n"
. "\n"
. "\n"
. "Student 2 Name: $FTGStudent_2_Name\n"
. "\n"
. "Agency: $FTGAgency\n"
. "\n"
. "Contact Person: $FTGContact_Person\n"
. "\n"
. "email address: $FTGemail_address\n"
. "\n"
. "";

$confEmailHeader = "From: bonniebruno@nycap.rr.com\n"
. "MIME-Version: 1.0\n"
. "Content-type: text/plain; charset=\"ISO-8859-1\"\n"
. "Content-transfer-encoding: 8bit\n";

mail($confEmailTo, $confEmailSubject, $confEmailBody, $confEmailHeader);
exit;
?>

 

Thanks for any help.  I'm sure the code is sloppy.  I get from a combination of internet search and books that I have.

Link to comment
Share on other sites

I tried that and still the same. 

When I do search I have 4 of the same e-mail address.  I will click on the radio button that says ID 9 which is in the first row of the search.  When it goes to the delete_course.php it shows ID 9 but then gives me the info in the last row of the search.

Link to comment
Share on other sites

Disregard this part.When I do search I have 4 of the same e-mail address.  I will click on the radio button that says ID 9 which is in the first row of the search.  When it goes to the delete_course.php it shows ID 9 but then gives me the info in the last row of the search. I have solved that.

It is still not deleting from the DB

Link to comment
Share on other sites

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.