Hello again. I was able to add to my database -- quick refresher of my situation:
http://www.experts-exchange.com/Web/Web_Languages/PHP/PHP_Databases/Q_21817323.html. Now I'm trying to delete. So far, I've been able to access the database and display on the screen the contents of the person table (person_id, firstname, middlename, and lastname). I don't think I'm deleting correctly. I modified the add code to try to make it delete -- I have a form where the user just types in the person_id, and clicks the "Submit" button (
http://img92.imageshack.us/img92/1529/delete4pc.png ):
$delquery[0] = "DELETE FROM person WHERE person_id = $person_id";
But, it's not deleting. Partial code:
--------------------------
----------
----------
----------
---
...
<?php
error_reporting(E_ALL);
session_start();
header("Pragma: no-cache");
include("util.php");
securityCheck();
$locationFeedback = " ";
$feedback = " ";
$isPostback = FALSE;
if (array_key_exists("Submit"
, $_REQUEST)) {
$isPostback = TRUE;
}
if ($isPostback) {
$person_id = getRequestValue("person_id
");
$validated = true;
if ($validated) {
// $sql = Array();
// $res = Array();
// $last_ids = Array();
$delquery = Array();
// $sql[0] = "INSERT INTO person (password, firstname, middlename, lastname) VALUES ('$password', '$firstname', '$middlename', '$lastname')";
// $sql[1] = "INSERT INTO member (person_id, employer, graduation_date, subnewsletter, email_address) VALUES (LAST_INSERT_ID(), '$employer', '$graduation_date', '$subnewsletter', '$email_address')";
// $sql[2] = "INSERT INTO phone (phone_number, member_id) VALUES ('$phone_number', LAST_INSERT_ID())";
$delquery[0] = "DELETE FROM person WHERE person_id = $person_id"; // <-------------- HERE IS THE LINE
// $delquery[1] = "DELETE FROM member WHERE person_id = ";
// $delquery[2] = "DELETE FROM phone WHERE phone_id = ";
// print_r ($sql);
$conn = getConnection();
$feedback = "Member deleted from database successfully.";
// for ($i = 0; $i < count($sql); ++$i) {
// $res[$i] = mysql_query($sql[$i], $conn);
// $last_ids[$i] = mysql_insert_id($conn);
// if (!$res[$i]) {
// $err = mysql_error ($conn);
// for ($j = $i-1; $j >= 0; -- $j) {
// mysql_query($delquery[$j] . $last_ids[$j]);
// }
// $feedback = "Error, unable to insert record into database: <br />$err";
// break;
// }
// }
}
echo $feedback;
}
?>
...
<!-- main content -->
<td width="924" valign=top class="style8">
<div style="margin: 20px"> <!-- InstanceBeginEditable name="EditRegion" -->
<p>Home -> Staff
View -> Delete A Member<span class="style47"></span></p
>
<p class="style46">Delete A Member From Database </p>
<?php
$isPostBack = true;
if ($isPostBack) {
$sql = "SELECT * FROM person";
}
//echo $sql;
$result = mysql_query($sql, getConnection());
if (mysql_num_rows($result) == 0) {
echo("<p style='color:red'>No members in database found.</p>");
}
else {
echo("<table border='1' cellspacing='0'>");
echo("<tr bgcolor='#99CCFF'><th>pers
on_id</th>
<th>First Name</th><th>Middle Name</th><th>Last Name</th></tr>");
while($row = mysql_fetch_array($result)
) {
echo("<tr>");
//person_id
$person_id = "$row[0]";
if (strlen(trim($person_id)) > 0) {
echo("<td>$person_id</td>"
);
}
else {
echo("<td>N/A</td>");
}
//firstname
$firstname = $row[2];
if (strlen(trim($firstname)) > 0) {
echo("<td>$firstname</td>"
);
}
else {
echo("<td>N/A</td>");
}
//middlename
$middlename = $row[3];
if (strlen(trim($middlename))
> 0) {
echo("<td>$middlename</td>
");
}
else {
echo("<td>N/A</td>");
}
//lastname
$lastname = $row[4];
if (strlen(trim($lastname)) > 0) {
echo("<td>$lastname</td>")
;
}
else {
echo("<td>N/A</td>");
}
echo("</tr>");
}
echo("</table>");
}
?>
<!-- Delete Form starts here -->
<p><span class="style44"></span></p
>
<form name="form1" method="post">
<table border="0">
<!-- This gathers information for the deletion. -->
<tr>
<th>Delete Member with person_id:</th>
<td><input name="person_id" id="person_id"><?php echo(getRequestValue("pers
on_id"))?>
</td>
</tr>
</table>
<br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Submit2" value="Clear">
<p align="center"> </p>
</form>
<p style="color:red"><?php echo($feedback); ?></p>
<!-- InstanceEndEditable -->
<p> </p>
<!-- Delete Form ends here -->
...
Thank you for any help :-)
Start Free Trial