PHP Login System with Admin Features

This forum was created to talk about the PHP Login System with admin features created by jpmaster77 on evolt's website


    Edit Saved Data

    Share
    avatar
    mbrad

    Number of posts : 42
    Registration date : 2009-02-19

    Edit Saved Data

    Post  mbrad on Sun Mar 08, 2009 12:18 am

    Thanks for taking the time to read my question.

    I have a page that displays contact information... phone numbers, mailing address and so on.

    At the top of each contact there is an edit button which I'd like to use to edit the associated contact info.

    I've been looking at the useredit.php file to try to figure out how to do this but am at a loss.

    phonebook.php looks like this: (not the best code I know, but I have it like this for error checking for the time being)
    Code:

    <?php
    $x="";
    while ($row = mysql_fetch_assoc($result)) {
       
       if ($x=="") {
       echo "<a id=\"top\" name=\"top\"></a>";
       echo "<table class=\"ContactTable\" border=\"0\" cellpadding=\"6\" cellspacing=\"2\">\n";
          echo "<tr>\n";
          echo "<td>";
          echo "<a class=\"ContactLetter\" name=\"" . substr($row['LastName'],0,1) . "\" id=\"" . substr($row['LastName'],0,1) . "\">" . substr($row['LastName'],0,1) . "</a>";
          echo "</td>\n";
          echo "</tr>\n";
          $x = substr($row['LastName'],0,1);
       }
       elseif ($x != substr($row['LastName'],0,1)) {
       echo "</table>\n";
       echo "<table class=\"ContactTable\" border=\"0\" cellpadding=\"6\" cellspacing=\"2\">\n";
          echo "<tr>\n";
          echo "<td>";
          echo "<a class=\"ContactLetter\" name=\"" . substr($row['LastName'],0,1) . "\" id=\"" . substr($row['LastName'],0,1) . "\">" . substr($row['LastName'],0,1) . "</a>";
          echo "</td>\n";
          echo "</tr>\n";
          $x = substr($row['LastName'],0,1);
       }
       echo "<tr>\n";
       echo "<td>";
       echo "<h3 class=\"ContactTitle\">" . $row['LastName'] . ", ". $row['FirstName'] . "</h3>";
       echo "</td>\n";
       echo "<td>";
       echo "<form action=\"process.php\" method=\"POST\"><input type=\"hidden\" name=\"rowIDCont\" value=\"" . $value . "\" /><input type=\"hidden\" name=\"subEditContact\" value=\"1\" /><input type=\"submit\" value=\"Edit\" /><span id=\"result\"" . $value . "\" style=\"display:none; background:green;\"></span><span>&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"#top\" class=\"TopLink\">Top</a></span></form>";
       echo "</td>\n";
       echo "</tr>\n";
       //echo "<tr>\n";
      foreach($row as $key => $value) {
       if ($key == 'LastName' && $value != "") {
       echo "<tr>\n";
       echo "<td class=\"ContactHeader\">";
       echo "Last Name";
       echo "</td>\n";
       echo "<td>";
       echo $value;
       echo "</td>\n";
       echo "</tr>\n";
       }
       elseif ($key == 'FirstName' && $value != "") {
       echo "<tr>\n";
       echo "<td class=\"ContactHeader\">";
       echo "First Name";
       echo "</td>\n";
       echo "<td>";
       echo $value;
       echo "</td>\n";
       echo "</tr>\n";
       }
       elseif ($key == 'Phone1' && $value != "") {
       echo "<tr>\n";
       echo "<td class=\"ContactHeader\">";
       echo "Phone 1";
       echo "</td>\n";
       echo "<td>";
       echo $value;
       echo "</td>\n";
       echo "</tr>\n";
       }
       elseif ($key == 'Phone2' && $value != "") {
       echo "<tr>\n";
       echo "<td class=\"ContactHeader\">";
       echo "Phone 2";
       echo "</td>\n";
       echo "<td>";
       echo $value;
       echo "</td>\n";
       echo "</tr>\n";
       }
       elseif ($key == 'Mobile1' && $value != "") {
       echo "<tr>\n";
       echo "<td class=\"ContactHeader\">";
       echo "Mobile 1";
       echo "</td>\n";
       echo "<td>";
       echo $value;
       echo "</td>\n";
       echo "</tr>\n";
       }
       elseif ($key == 'Mobile2' && $value != "") {
       echo "<tr>\n";
       echo "<td class=\"ContactHeader\">";
       echo "Mobile 2";
       echo "</td>\n";
       echo "<td>";
       echo $value;
       echo "</td>\n";
       echo "</tr>\n";
       }
       elseif ($key == 'emailadd' && $value != "") {
       echo "<tr>\n";
       echo "<td class=\"ContactHeader\">";
       echo "Email 1";
       echo "</td>\n";
       echo "<td>";
       echo $value;
       echo "</td>\n";
       echo "</tr>\n";
       }
       elseif ($key == 'emailadd2' && $value != "") {
       echo "<tr>\n";
       echo "<td class=\"ContactHeader\">";
       echo "Email 2";
       echo "</td>\n";
       echo "<td>";
       echo $value;
       echo "</td>\n";
       echo "</tr>\n";
       }         
       elseif ($key == 'Country' && $value != "") {
       echo "<tr>\n";
       echo "<td class=\"ContactHeader\">";
       echo "Country";
       echo "</td>\n";
       echo "<td>";
       echo $value;
       echo "</td>\n";
       echo "</tr>\n";
       }
       elseif ($key == 'Address' && $value != "") {
       echo "<tr>\n";
       echo "<td class=\"ContactHeader\">";
       echo "Address";
       echo "</td>\n";
       echo "<td>";
       echo $value;
       echo "</td>\n";
       echo "</tr>\n";
       }
       elseif ($key == 'PostalZipCode' && $value != "") {
       echo "<tr>\n";
       echo "<td class=\"ContactHeader\">";
       echo "Postal / Zip Code";
       echo "</td>\n";
       echo "<td>";
       echo $value;
       echo "</td>\n";
       echo "</tr>\n";
       }
       elseif ($key == 'ProvState' && $value != "") {
       echo "<tr>\n";
       echo "<td class=\"ContactHeader\">";
       echo "Prov / State";
       echo "</td>\n";
       echo "<td>";
       echo $value;
       echo "</td>\n";
       echo "</tr>\n";
       }
       elseif ($key == 'City' && $value != "") {
       echo "<tr>\n";
       echo "<td class=\"ContactHeader\">";
       echo "City";
       echo "</td>\n";
       echo "<td>";
       echo $value;
       echo "</td>\n";
       echo "</tr>\n";
       }
       elseif ($key == 'Notes' && $value != "") {
       echo "<tr>\n";
       echo "<td class=\"ContactHeader\">";
       echo "Notes";
       echo "</td>\n";
       echo "<td>";
       echo $value;
       echo "</td>\n";
       echo "</tr>\n";
       }
      }
    }
    echo "</table>\n";
    ?>
    </div>
    <?php

    This is my process.php code that pertains to my problem
    Code:

         /* User submitted Edit Contact Request */    //***************************Added This**************************************
          else if(isset($_POST['subEditContact'])){
           $this->procEditContact();
          }



      function procEditContact(){
          global $database, $session, $form;
          /* Account edit attempt */
          echo "<script>alert('Got Here');</script>";
        
         //This $retval is from useredit
         //$retval = $session->editAccount($_POST['curpass'], $_POST['newpass'], $_POST['email'], $_POST['UsrAvitar'], $_POST['UsrAvitarPath']);
         $q = "SELECT `LastName`, `FirstName`, `Phone1`, `Phone2`, `Mobile1`, `Mobile2`, `emailadd`, `emailadd2`, `Country`, `Address`, `PostalZipCode`, `ProvState`, `City`, `Notes`, `tblContactID` FROM `tblcontact` WHERE `tblContactID`=".$_POST['rowIDCont'];
         $retval = $database->query($q);
        
          //*********************Now how do I get it in the form on my page edit_contact.php********************
          header("Location: ".$session->referrer);
      }

    Now how do I get the data into my form on my page edit_contact.php?

    form on edit_contact.php
    Code:

    <form action="process.php" method="POST">
             <table border="0" cellspacing="0" cellpadding="3" id="NewMessage">
                <tr>
                       <td>Last Name:</td><td><input id="lastname" name="lastname" value="<?php echo $form->value("LastName"); ?>" /></td><td><?php echo $form->error("lastname"); ?></td>
                        <td>First Name:</td><td><input id="firstname" name="firstname" value="<?php echo $form->value("FirstName"); ?>" /></td><td><?php echo $form->error("firstname"); ?></td>
                        <td>&nbsp;</td>
                </tr>
                    <tr>
                       <td>Phone 1:</td><td><input id="phone1" name="phone1" value="<?php echo $form->value("Phone1"); ?>" /></td><td><?php echo $form->error("phone1"); ?></td>
                   <td>Phone 2:</td><td><input id="phone2" name="phone2" value="<?php echo $form->value("Phone2"); ?>" /></td><td><?php echo $form->error("phone2"); ?></td>
                        <td>&nbsp;</td>
                </tr>
                    <tr>                   
                        <td>Mobile 1:</td><td><input id="mobile1" name="mobile1" value="<?php echo $form->value("Mobile1"); ?>" /></td><td><?php echo $form->error("mobile1"); ?></td>
                        <td>Mobile 2:</td><td><input id="mobile2" name="mobile2" value="<?php echo $form->value("Mobile2"); ?>" /></td><td><?php echo $form->error("mobile2"); ?></td>
                       
                        <td>&nbsp;</td>
                </tr>
                    <tr>                   
                        <td>E-mail 1:</td><td><input id="emailadd" name="emailadd" value="<?php echo $form->value("emailadd"); ?>" /></td><td><?php echo $form->error("emailadd"); ?></td>
                        <td>E-mail 2:</td><td><input id="emailadd2" name="emailadd2" value="<?php echo $form->value("emailadd2"); ?>" /></td><td><?php echo $form->error("emailadd2"); ?></td>
                        <td>&nbsp;</td>
                </tr>
                    <tr>                   
                        <td>Country:</td><td><input id="country" name="country" value="<?php echo $form->value("Country"); ?>" /></td><td><?php echo $form->error("country"); ?></td>
                        <td>Prov/State:</td><td><input id="provstate" name="provstate" value="<?php echo $form->value("ProvState"); ?>" /></td><td><?php echo $form->error("provstate"); ?></td>
                        <td>&nbsp;</td>
                </tr>
                    <tr>                   
                        <td>City:</td><td><input id="city" name="city" value="<?php echo $form->value("City"); ?>" /></td><td><?php echo $form->error("city"); ?></td>
                        <td>Address:</td><td><input id="address" name="address" value="<?php echo $form->value("Address"); ?>" /></td><td><?php echo $form->error("address"); ?></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                       <td>Postal/Zip:</td><td><input id="postalzip" name="postalzip" value="<?php echo $form->value("PostalZipCode"); ?>" /></td><td><?php echo $form->error("postalzip"); ?></td>
                        <td>Notes:</td><td><input id="notes" name="notes" value="<?php echo $form->value("Notes"); ?>" /></td><td><?php echo $form->error("notes"); ?></td>
                        <td>&nbsp;</td><td align="right"><input type="hidden" id="subNewContact" name="subNewContact" value="1" /><input type="submit" value="Save" /></td>
                    </tr>
                </table>
          </form>

      Current date/time is Mon Dec 11, 2017 7:01 pm