Advertisement

04.20.2006 at 03:50AM PDT, ID: 21820519
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.4

PHP Beginner: Deleting a record from the database

Asked by luna621 in PHP and Databases

Tags: ,

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 = "&nbsp;";
      $feedback = "&nbsp;";

      $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 -&gt; Staff
        View -&gt; 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>person_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("person_id"))?></td>
          </tr>
        </table>
          <br>
          <input type="submit" name="Submit" value="Submit">
          <input type="reset" name="Submit2" value="Clear">
          <p align="center">&nbsp;</p>
        </form>
                        <p style="color:red"><?php echo($feedback); ?></p>
        <!-- InstanceEndEditable -->
        <p>&nbsp;</p>

<!-- Delete Form ends here -->
...


Thank you for any help :-)Start Free Trial
 
Loading Advertisement...
 
[+][-]04.20.2006 at 04:07AM PDT, ID: 16496596

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2006 at 04:08AM PDT, ID: 16496606

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2006 at 04:09AM PDT, ID: 16496613

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2006 at 04:12AM PDT, ID: 16496628

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2006 at 04:14AM PDT, ID: 16496639

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2006 at 04:14AM PDT, ID: 16496640

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2006 at 04:14AM PDT, ID: 16496641

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2006 at 04:16AM PDT, ID: 16496652

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2006 at 04:18AM PDT, ID: 16496662

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: PHP and Databases
Tags: php, ispostback
Sign Up Now!
Solution Provided By: RQuadling
Participating Experts: 2
Solution Grade: A
 
 
[+][-]04.20.2006 at 04:20AM PDT, ID: 16496699

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2006 at 04:22AM PDT, ID: 16496748

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2006 at 04:23AM PDT, ID: 16496756

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2006 at 04:25AM PDT, ID: 16496798

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2006 at 04:25AM PDT, ID: 16496807

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2006 at 04:28AM PDT, ID: 16496826

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]04.20.2006 at 04:32AM PDT, ID: 16496882

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2006 at 04:33AM PDT, ID: 16496894

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2006 at 04:34AM PDT, ID: 16496910

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2006 at 04:35AM PDT, ID: 16496940

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2006 at 04:38AM PDT, ID: 16496996

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32