Ok this is what ive tried to make my delete function work.
Ive put this in:
Code: Select all
if($_POST['action'] == "delete"){
$delete = mysql_query("DELETE FROM people WHERE person_id = '$person_id'") or die(mysql_error()); }
and Ive created this button
Code: Select all
<form action=\"e;editpeople.php\"e; method=\"e;post\"e;>
<input type=\"e;hidden\"e; name=\"e;action\"e; value=\"e;delete\"e;>
<input type=\"e;submit\"e; value=\"e;delete\"e;>
</form>
this produces two text boxes which contain the words delete
can someone please advice me on where I am gogin wrong,
In short I can already update my records and save them - I thought I would be able to add a delete function to the same edit page.
Above is the advice I was given which isnt working.
here is my code in full
lines 39-40 and 456 to 459 are the key bits of code
Code: Select all
<?php
/* Connecting, selecting database */
$link = mysql_connect("*****", "*****", "******")
or die("Could not connect : " . mysql_error());
echo "";
mysql_select_db("contact_management_system") or die("Could not select database");
if(isset($_GET['person_id'])){
$person_id=$_GET['person_id'];
}
if ($_POST['Submit'] == 'Save'){
foreach ($_POST as $formName => $phpName){
$$formName = $phpName;
}
$sql ="UPDATE people SET "
. " salutation='" .$salutation."',"
. " firstname='" .$firstname ."',"
. " surname='" .$surname."',"
. " organisation='" .$organisation ."',"
. " role='" .$role."',"
. " address1='" . $address1."',"
. " address2='" .$address2."',"
. " city='" .$city."',"
. " telephone='" .$telephone."',"
. " mobile='" . $mobile ."',"
. " fax='" .$fax."',"
. " dateoflastcontact='" .$dateoflastcontact."',"
. " datecontactagain='" .$datecontactagain."',"
. " notes='" .$notes."',"
. " email='" .$email."',"
. " org_id='" . $org_id ."'"
. " WHERE person_id='" . $person_id."'";
if ($_POST['action'] == "delete"){
$delete = mysql_query("DELETE FROM people WHERE person_id = '$person_id'") or die(mysql_error()); }
echo "<br><div align=center>" . $sql . "<br>";
mysql_query($sql) or die('could not insert' . mysql_error());
echo " <div align=left><table width=70% border=1 cellpadding=10 align=center>"
. " <tr>"
. " <td width=40%>"
. " <font face=arial size=2><b>"
. " person_id"
. " </font>"
. " </td>"
. " <td>"
. " <font face=arial size=2>"
. " " . $person_id . " </font>"
. " </td>"
. " </tr>"
. " <tr>"
. " <td>"
. " <font face=arial size=2><b>"
. " salutation"
. " </font>"
. " </td>"
. " <td>"
. " <font face=arial size=2>"
. " " . $salutation . "</font>"
. " </td>"
. " </tr>"
. " <tr>"
. " <td>"
. " <font face=arial size=2><b>"
. " firstname"
. " </font>"
. " </td>"
. " <td>"
. " <font face=arial size=2>"
. " " . $firstname . "</font>"
. " </td>"
. " </tr>"
. " <tr>"
. " <td>"
. " <font face=arial size=2><b>"
. " surname"
. " </font>"
. " </td>"
. " <td>"
. " <font face=arial size=2>"
. " " . $surname . "</font>"
. " </td>"
. " </tr>"
. " <tr>"
. " <td>"
. " <font face=arial size=2><b>"
. " organisation"
. " </font>"
. " </td>"
. " <td>"
. " <font face=arial size=2>"
. " " . $organisation . "</font>"
. " </td>"
. " </tr>"
. " <tr>"
. " <td>"
. " <font face=arial size=2><b>"
. " role"
. " </font>"
. " </td>"
. " <td>"
. " <font face=arial size=2>"
. " " . $role . "</font>"
. " </td>"
. " </tr>"
. " <tr>"
. " <td>"
. " <font face=arial size=2><b>"
. " address1"
. " </font>"
. " </td>"
. " <td>"
. " <font face=arial size=2>"
. " " . $address2 . "</font>"
. " </td>"
. " </tr>"
. " <tr>"
. " <td>"
. " <font face=arial size=2><b>"
. " city"
. " </font>"
. " </td>"
. " <td>"
. " <font face=arial size=2>"
. " " . $city . "</font>"
. " </td>"
. " </tr>"
. " <tr>"
. " <td>"
. " <font face=arial size=2><b>"
. " postcode"
. " </font>"
. " </td>"
. " <td>"
. " <font face=arial size=2>"
. " " . $postcode . "</font>"
. " </td>"
. " </tr>"
. " <tr>"
. " <td>"
. " <font face=arial size=2><b>"
. " telephone"
. " </font>"
. " </td>"
. " <td>"
. " <font face=arial size=2>"
. " " . $telephone . "</font>"
. " </td>"
. " </tr>"
. " <tr>"
. " <td>"
. " <font face=arial size=2><b>"
. " mobile"
. " </font>"
. " </td>"
. " <td>"
. " <font face=arial size=2>"
. " " . $mobile . "</font>"
. " </td>"
. " </tr>"
." <tr>"
. " <td>"
. " <font face=arial size=2><b>"
. " fax"
. " </font>"
. " </td>"
. " <td>"
. " <font face=arial size=2>"
. " " . $fax . "</font>"
. " </td>"
. " </tr>"
. " <tr>"
. " <td>"
. " <font face=arial size=2><b>"
. " dateoflastcontact"
. " </font>"
. " </td>"
. " <td>"
. " <font face=arial size=2>"
. " " . $dateoflastcontact . "</font>"
. " </td>"
. " </tr>"
. " <tr>"
. " <td>"
. " <font face=arial size=2><b>"
. " datecontactagain"
. " </font>"
. " </td>"
. " <td>"
. " <font face=arial size=2>"
. " " . $datecontactagain . "</font>"
. " </td>"
. " </tr>"
. " <tr>"
. " <td>"
. " <font face=arial size=2><b>"
. " notes"
. " </font>"
. " </td>"
. " <td>"
. " <font face=arial size=2>"
. " " . $notes . "</font>"
. " </td>"
. " </tr>"
. " <tr>"
. " <td>"
. " <font face=arial size=2><b>"
. " email"
. " </font>"
. " </td>"
. " <td>"
. " <font face=arial size=2>"
. " " . $email . "</font>"
. " </td>"
. " </tr>"
. " <tr>"
. " <td>"
. " <font face=arial size=2><b>"
. " org_id"
. " </font>"
. " </td>"
. " <td>"
. " <font face=arial size=2>"
. " " . $org_id . "</font>"
. " </td>"
. " </tr>"
. " </table>";
}
$sql = "SELECT * FROM people WHERE person_id='" . $person_id . "'";
echo "<br><div align=center>" . $sql . "<br>";
$memb = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($memb);
echo "\n"
. " </div>\n"
. " <form name=form2 method=post action=editpeople.html?person_id=" . $person_id . ">\n"
. " <table width=70% border=1 cellpadding=10 align=center>\n"
. " <tr>\n"
. " <td width=40%>\n"
. " <font face=arial size=2><b>\n"
. " Person ID\n"
. " </font>\n"
. " </td>\n"
. " <td>\n"
. " <font face=arial size=2>\n"
. " <input name=person_id type=text id=person_id value='" . $row['person_id'] . "'></font>\n"
. " </td>\n"
. " </tr>\n"
. " <tr>\n"
. " <td width=40%>\n"
. " <font face=arial size=2><b>\n"
. " Salutation\n"
. " </font>\n"
. " </td>\n"
. " <td>\n"
. " <font face=arial size=2>\n"
. " <input name=salutation type=text id=salutation value='" . $row['salutation'] . "'></font>\n"
. " <tr>\n"
. " <td width=40%>\n"
. " <font face=arial size=2><b>\n"
. " First Name\n"
. " </font>\n"
. " </td>\n"
. " <td>\n"
. " <font face=arial size=2>\n"
. " <input name=firstname type=text id=firstname value='" . $row['firstname'] . "'></font>\n"
. " </td>\n"
. " </tr>\n"
. " <tr>\n"
. " <td>\n"
. " <font face=arial size=2><b>\n"
. " Surame\n"
. " </font>\n"
. " </td>\n"
. " <td>\n"
. " <font face=arial size=2>\n"
. " <input name=surname type=text id=surname value='" . $row['surname'] . "'></font>\n"
. " </td>\n"
. " </tr>\n"
. " <tr>\n"
. " <td>\n"
. " <font face=arial size=2><b>\n"
. " Organisation\n"
. " </font>\n"
. " </td>\n"
. " <td>\n"
. " <font face=arial size=2>\n"
. " <input name=organisation type=text id=organsation value='" . $row['organisation'] . "'></font>\n"
. " </td>\n"
. " </tr>\n"
. " <tr>\n"
. " <td>\n"
. " <font face=arial size=2><b>\n"
. " Role \n"
. " </font>\n"
. " </td>\n"
. " <td>\n"
. " <font face=arial size=2>\n"
. " <input name=role type=text id=role value='" .
$row['role'] . "'></font>\n"
. " </td>\n"
. " </tr>\n"
. " <tr>\n"
. " <td>\n"
. " <font face=arial size=2><b>\n"
. " Address 1\n"
. " </font>\n"
. " </td>\n"
. " <td>\n"
. " <font face=arial size=2>\n"
. " <input name=address1 type=text id=address1 value='" . $row['address1'] . "'></font>\n"
. " </td>\n"
. " </tr>\n"
. " <tr>\n"
. " <td>\n"
. " <font face=arial size=2><b>\n"
. " Address2\n"
. " </font>\n"
. " </td>\n"
. " <td>\n"
. " <font face=arial size=2>\n"
. " <input name=address2 type=text id=address2 value='" . $row['address2'] . "'></font>\n"
. " </td>\n"
. " </tr>\n"
. " <tr>\n"
. " <td>\n"
. " <font face=arial size=2><b>\n"
. " City\n"
. " </font>\n"
. " </td>\n"
. " <td>\n"
. " <font face=arial size=2>\n"
. " <input name=city type=text id=city value='" .
$row['city'] . "'></font>\n"
. " </td>\n"
. " </tr>\n"
. " <tr>\n"
. " <td>\n"
. " <font face=arial size=2><b>\n"
. " Telephone\n"
. " </font>\n"
. " </td>\n"
. " <td>\n"
. " <font face=arial size=2>\n"
. " <input name=telephone type=text id=telephone value='" . $row['telephone'] . "'></font>\n"
. " </td>\n"
. " </tr>\n"
. " <tr>\n"
. " <td>\n"
. " <font face=arial size=2><b>\n"
. " Mobile\n"
. " </font>\n"
. " </td>\n"
. " <td>\n"
. " <font face=arial size=2>\n"
. " <input name=mobile type=text id=mobile value='" .
$row['mobile'] . "'></font>\n"
. " </td>\n"
. " </tr>\n"
. " <tr>\n"
. " <td>\n"
. " <font face=arial size=2><b>\n"
. " Fax\n"
. " </font>\n"
. " </td>\n"
. " <td>\n"
. " <font face=arial size=2>\n"
. " <input name=fax type=text id=fax value='" .
$row['fax'] . "'></font>\n"
. " </td>\n"
. " </tr>\n"
. " <tr>\n"
. " <td>\n"
. " <font face=arial size=2><b>\n"
. " Last Contact\n"
. " </font>\n"
. " </td>\n"
. " <td>\n"
. " <font face=arial size=2>\n"
. " <input name=dateoflastcontact type=text id=dateoflastcontact value='" .
$row['dateoflastcontact'] . "'></font>\n"
. " </td>\n"
. " </tr>\n"
. " <tr>\n"
. " <td>\n"
. " <font face=arial size=2><b>\n"
. " Contact Again\n"
. " </font>\n"
. " </td>\n"
. " <td>\n"
. " <font face=arial size=2>\n"
. " <input name=datecontactagain type=text id=datecontactagain value='" .
$row['datecontactagain'] . "'></font>\n"
. " </td>\n"
. " </tr>\n"
. " <tr>\n"
. " <td>\n"
. " <font face=arial size=2><b>\n"
. " Notes\n"
. " </font>\n"
. " </td>\n"
. " <td>\n"
. " <font face=arial size=2>\n"
. " <input name=notes type=text id=notes value='" .
$row['notes'] . "'></font>\n"
. " </td>\n"
. " </tr>\n"
. " <tr>\n"
. " <td>\n"
. " <font face=arial size=2><b>\n"
. " Email\n"
. " </font>\n"
. " </td>\n"
. " <td>\n"
. " <font face=arial size=2>\n"
. " <input name=email type=text id=email value='" .
$row['email'] . "'></font>\n"
. " </td>\n"
. " </tr>\n"
. " <tr>\n"
. " <td>\n"
. " <font face=arial size=2><b>\n"
. " OID\n"
. " </font>\n"
. " </td>\n"
. " <td>\n"
. " <font face=arial size=2>\n"
. " <input name=org_id type=text id=org_id value='" .
$row['org_id'] . "'></font>\n"
. " </td>\n"
. " </tr>\n"
. " <tr>\n"
. " <td colspan=2>\n"
. "  \n"
. " </td>\n"
. " </tr>\n"
. " <tr>\n"
. " <td colspan=2 align=center>\n"
. " <input type=reset name=Reset value=Reset>\n"
. " <input type=submit name=Submit
value=Save>\n"
. " </td>\n"
. " </tr>\n"
. " </table>\n"
. " </form>\n";
// }
?>
<form action=\"editpeople.php\" method=\"post\">
<input type=\"hidden\" name=\"action\" value=\"delete\">
<input type=\"submit\" value=\"delete\">
</form>
</td>
<p>