Results 1 to 3 of 3

Thread: PHP/MySQL Form Help for the Frustrated

  1. #1
    rickpugh's Avatar
    rickpugh is offline Practically a Glow Sage
    Join Date
    Apr 2005
    Location
    Simi Valley, California, United States
    Posts
    21

    Question PHP/MySQL Form Help for the Frustrated

    Hi Team,

    Not sure if this is the right forum for this question so feel free to move it if I am in the wrong place...

    So here is my problem... I have a form that allows me to edit a member's information that I have stored in my DB. Before getting to this form, the user searches on a last name to identify the record to edit. Once selected, this is the form that is displayed:

    Sorry in advance it is a long form with a lot of information....

    PHP Code:
    <?php 
    // Create a variable for the Database ID of the member selected to edit
    $member_edit $_POST['member_edit'];
    //Check to make sure a member was actually selected to edit
    if ($member_edit == "")
    {
    echo 
    "<p>You must select a member before you can edit.  Please use the back button and try again.";
    exit;

    //Now we can connect to the Database
    $hostname "localhost"// Our DB server.
    $username "XXXXXXX"// The username for the database.
    $password "XXXXXXX"// The password for the username above.
    $table "XXXXX"// The name of the table we are working with.
    $dbname "XXXXX"// This name of the database the table belongs to.
    MYSQL_CONNECT($hostname$username$password) OR DIE("DB connection unavailable");
    @
    mysql_select_db"$dbname") or die( "Unable to select database");
    //We query the DB for the selected member 
    $query mysql_query("  SELECT `application_date`, `applicant_fname`, `applicant_lname`, `street1`, `street2`, `city`, `state`, `zipcode`, `phone`, `email`, `profession`, `skills`, `membership`, `family_fname1`, `family_lname1`, `family_relationship1`, `family_fname2`, `family_lname2`, `family_relationship2`, `family_fname3`, `family_lname3`, `family_relationship3`, `family_fname4`, `family_lname4`, `family_relationship4`, `family_fname5`, `family_lname5`, `family_relationship5`, `family_fname6`, `family_lname6`, `family_relationship6`, `consent_signature`, `member_bal_prev`, `member_cur_dues`, `member_amt_billed`, `member_amt_paid`, `member_bal_due`, `member_status`, `member_title`, `member_notes`, `ID`
    FROM `jos_membership` WHERE `ID` ='
    $member_edit' LIMIT 0 , 30  ");
    //We build variables for each of the DB Result Values so that we can edit and then update them.
    while ($row = @mysql_fetch_array($query)) {
     
    $application_date $row["application_date"];
     
    $applicant_fname $row["applicant_fname"];
     
    $applicant_lname $row["applicant_lname"];
     
    $street1 $row["street1"];
     
    $street2 $row["street2"];
     
    $city $row["city"];
     
    $state $row["state"];
     
    $zipcode $row["zipcode"];
     
    $phone $row["phone"];
     
    $email $row["email"];
     
    $profession $row["profession"];
     
    $skills $skills["skills"];
     
    $membership $row["membership"];
     
    $family_fname1 $row["family_fname1"];
     
    $family_lname1 $row["family_lname1"];
     
    $family_relationship1 $row["family_relationship1"];
     
    $family_fname2 $row["family_fname2"];
     
    $family_lname2 $row["family_lname2"];
     
    $family_relationship2 $row["family_relationship2"];
     
    $family_fname3 $row["family_fname3"];
     
    $family_lname3 $row["family_lname3"];
     
    $family_relationship3 $row["family_relationship3"];
     
    $family_fname4 $row["family_fname4"];
     
    $family_lname4 $row["family_lname4"];
     
    $family_relationship4 $row["family_relationship4"];
     
    $family_fname5 $row["family_fname5"];
     
    $family_lname5 $row["family_lname5"];
     
    $family_relationship5 $row["family_relationship5"];
     
    $family_fname6 $row["family_fname6"];
     
    $family_lname6 $row["family_lname6"];
     
    $family_relationship6 $row["family_relationship6"];
     
    $consent_signature $row["consent_signature"];
     
    $member_bal_prev $row["member_bal_prev"];
     
    $member_cur_dues $row["member_cur_dues"];
     
    $member_amt_billed $row["member_amt_billed"];
     
    $member_amt_paid $row["member_amt_paid"];
     
    $member_bal_due $row["member_bal_due"];
     
    $member_status $row["member_status"];
     
    $member_title $row["member_title"];
     
    $member_notes $row["member_notes"];
     
    $ID $row["ID"];
    }
    //Check to make sure there is actually data returned to edit
    $anymatches mysql_num_rows($query);
    if (
    $anymatches == 0)
    {
    echo 
    "<h2>No records were returned from the database</h2><br>";
    }
    ?>
    <br /><br />
    <h2>Edit Member Data</h2>
    <br />
    <p>Edit the member's data below and then select "Save".  If you have reached this page in error or do not wish to commit your changes please slect "Cancel"</p>
    <br>
    <fieldset>
     <legend>Member Information</legend>
     <table>
      <tr>
       <td><label for="applicant_fname">First Name</label></td>
       <td><input type="text" name="applicant_fname" id="applicant_fname" value="<?php print $applicant_fname ?>" size="30" maxlength="50"></td>
       <td><label for="applicant_lname">Last Name</label></td>
       <td><input type="text" name="applicant_lname" id="applicant_lname" value="<?php print $applicant_lname ?>"size="30" maxlength="50"></td>
       <td><label for="ID">Member ID:</label></td>
       <td><?php print $ID ?></td>
      </tr>
     </table>
    </fieldset>
    <fieldset>
     <legend>Membership Type</legend>
     <table>
      <tr>
       <td><label for="member_date">Initial Membership Date:</label><br>(YYYY-MM-DD)</td>
       <td><input type="text" name="application_date" id="application_date" value="<?php print $application_date ?>"size="10" maxlength="10"></td>
       <td><label for="member_status">Membership Status:</label></td>
       <td><select name="member_status" id="member_status" size="1">
         <option value="Select One" <?php if ($member_status == '') {print 'selected';} ?>>- Select One -</option>
         <option value="Active" <?php if ($member_status == 'Active') {print 'selected';} ?>>Active</option>
         <option value="Inactive" <?php if ($member_status == 'Inactive') {print 'selected';} ?>>Inactive</option>
         <option value="Suspended" <?php if ($member_status == 'Suspended') {print 'selected';} ?>>Suspended</option>
         </select></td>
      </tr>
      <tr>
       <td><label for="membership_type">Membership Type:</label>
       <td><?php print $membership ?><input type="hidden" name="ID" id="ID" value="<?php print $membership ?>"></td>
       <td><label for="member_title">VCFPA Officer Title:</label></td>
       <td><select name="member_title" id="member_title" size="1">
         <option value="Select One" <?php if ($member_title == '') {print 'selected';} ?>>- Select One -</option>
         <option value="President" <?php if ($member_title == 'President') {print 'selected';} ?>>President</option>
         <option value="Vice President" <?php if ($member_title == 'Vice President') {print 'selected';} ?>>Vice President</option>
         <option value="Treasurer" <?php if ($member_title == 'Treasurer') {print 'selected';} ?>>Treasurer</option>
         <option value="Secretary" <?php if ($member_title == 'Secretary') {print 'selected';} ?>>Secretary</option>
         <option value="Director" <?php if ($member_title == 'Director') {print 'selected';} ?>>Director</option>
         <option value="Chairmanship" <?php if ($member_title == 'Chairmanship') {print 'selected';} ?>>Chairmanship</option>
         <option value="Membership Coordinator" <?php if ($member_title == 'Membership Coordinator') {print 'selected';} ?>>Membership Coordinator</option>
         <option value="Webmaster" <?php if ($member_title == 'Webmaster') {print 'selected';} ?>>Web and Technology</option>
        </select></td>
      </tr>
      <tr>
       <td align="left" colspan="4"><label for="member_notes">Remarks/Notes:</label></td>
      </tr>
      <tr>
       <td align="left" colspan="4"><textarea cols="75" rows="10" name="member_notes" id="member_notes"><?php print $member_notes ?></textarea></td>
      </tr>
     </table>
    </fieldset>
    <fieldset>
     <legend>Account Information</legend>
     <table>
      <tr>
       <td><label for="member_bal_prev">Previous Balance:</label></td>
       <td>$<input type="text" name="member_bal_prev" id="member_bal_prev" value="<?php print $member_bal_prev ?>" size="7" maxlength="7"></td>
      </tr>
      <tr>
       <td><label for="member_cur_dues">Current Membership Dues:</label></td>
       <td>$<input type="text" name="member_cur_dues" id="member_cur_dues" value="<?php print $member_cur_dues ?>" size="7" maxlength="7"></td>
      </tr>
      <tr>
       <td><label for="member_amt_billed">Amount Billed:</label></td>
       <td>$<input type="text" name="member_amt_billed" id="member_amt_billed" value="<?php print $member_amt_billed ?>" size="7" maxlength="7"></td>
      </tr>
      <tr>
       <td><label for="member_amt_paid">Amount Paid:</label></td>
       <td>$<input type="text" name="member_amt_paid" id="member_amt_paid" value="<?php print $member_amt_paid ?>" size="7" maxlength="7"></td>
      </tr>
      <tr>
       <td><label for="member_bal_due">Balace Due:</label></td>
       <td>$<input type="text" name="member_bal_due" id="member_bal_due" value="<?php print $member_bal_due ?>" size="7" maxlength="7"></td>
      </tr>
     </table>
    </fieldset>
    <fieldset>
     <legend>Contact Information</legend>
     <table>
      <tr>
       <td><label for="street1">Street Address</label></td>
       <td><input type="text" name="street1" id="street1" value="<?php print $street1 ?>" size="30" maxlength="100"></td>
       <td><label for="street2">Apt/Suite</label></td>
       <td colspan="3"><input type="text" name="street2" id="street2" value="<?php print $street2 ?>" size="10" maxlength="25"></td>
      </tr>
      <tr>
       <td><label for="city">City</label></td>
       <td><input type="text" name="city" id="city" value="<?php print $city ?>" size="30" maxlength="100"></td>
       <td><label for="state">State</label></td>
       <td><select name="state" id="state">      
         <option value="XX" <?php if ($state == '') {print 'selected';} ?>>- Select One -
         <option value="AL" <?php if ($state == 'AL') {print 'selected';} ?>>AL</option>
         <option value="AK" <?php if ($state == 'AK') {print 'selected';} ?>>AK</option>
         <option value="AZ" <?php if ($state == 'AZ') {print 'selected';} ?>>AZ</option>
         <option value="AR" <?php if ($state == 'AR') {print 'selected';} ?>>AR</option>
         <option value="CA" <?php if ($state == 'CA') {print 'selected';} ?>>CA</option>
         <option value="CO" <?php if ($state == 'CO') {print 'selected';} ?>>CO</option>
         <option value="CT" <?php if ($state == 'CT') {print 'selected';} ?>>CT</option>
         <option value="DE" <?php if ($state == 'DE') {print 'selected';} ?>>DE</option>
         <option value="DC" <?php if ($state == 'DC') {print 'selected';} ?>>DC</option>
         <option value="FL" <?php if ($state == 'FL') {print 'selected';} ?>>FL</option>
         <option value="GA" <?php if ($state == 'GA') {print 'selected';} ?>>GA</option>
         <option value="HI" <?php if ($state == 'HI') {print 'selected';} ?>>HI</option>
         <option value="ID" <?php if ($state == 'ID') {print 'selected';} ?>>ID</option>
         <option value="IL" <?php if ($state == 'IL') {print 'selected';} ?>>IL</option>
         <option value="IN" <?php if ($state == 'IN') {print 'selected';} ?>>IN</option>
         <option value="IA" <?php if ($state == 'IA') {print 'selected';} ?>>IA</option>
         <option value="KS" <?php if ($state == 'KS') {print 'selected';} ?>>KS</option>
         <option value="KY" <?php if ($state == 'KY') {print 'selected';} ?>>KY</option>
         <option value="LA" <?php if ($state == 'LA') {print 'selected';} ?>>LA</option>
         <option value="ME" <?php if ($state == 'ME') {print 'selected';} ?>>ME</option>
         <option value="MD" <?php if ($state == 'MD') {print 'selected';} ?>>MD</option>
         <option value="MA" <?php if ($state == 'MA') {print 'selected';} ?>>MA</option>
         <option value="MI" <?php if ($state == 'MI') {print 'selected';} ?>>MI</option>
         <option value="MN" <?php if ($state == 'MN') {print 'selected';} ?>>MN</option>
         <option value="MS" <?php if ($state == 'MS') {print 'selected';} ?>>MS</option>
         <option value="MO" <?php if ($state == 'MO') {print 'selected';} ?>>MO</option>
         <option value="MT" <?php if ($state == 'MT') {print 'selected';} ?>>MT</option>
         <option value="NE" <?php if ($state == 'NE') {print 'selected';} ?>>NE</option>
         <option value="NV" <?php if ($state == 'NV') {print 'selected';} ?>>NV</option>
         <option value="NH" <?php if ($state == 'NH') {print 'selected';} ?>>NH</option>
         <option value="NJ" <?php if ($state == 'NJ') {print 'selected';} ?>>NJ</option>
         <option value="NM" <?php if ($state == 'NM') {print 'selected';} ?>>NM</option>
         <option value="NY" <?php if ($state == 'NY') {print 'selected';} ?>>NY</option>
         <option value="NC" <?php if ($state == 'NC') {print 'selected';} ?>>NC</option>
         <option value="ND" <?php if ($state == 'ND') {print 'selected';} ?>>ND</option>
         <option value="OH" <?php if ($state == 'OH') {print 'selected';} ?>>OH</option>
         <option value="OK" <?php if ($state == 'OK') {print 'selected';} ?>>OK</option>
         <option value="OR" <?php if ($state == 'OR') {print 'selected';} ?>>OR</option>
         <option value="PA" <?php if ($state == 'PA') {print 'selected';} ?>>PA</option>
         <option value="RI" <?php if ($state == 'RI') {print 'selected';} ?>>RI</option>
         <option value="SC" <?php if ($state == 'SC') {print 'selected';} ?>>SC</option>
         <option value="SD" <?php if ($state == 'SD') {print 'selected';} ?>>SD</option>
         <option value="TN" <?php if ($state == 'TN') {print 'selected';} ?>>TN</option>
         <option value="TX" <?php if ($state == 'TX') {print 'selected';} ?>>TX</option>
         <option value="UT" <?php if ($state == 'UT') {print 'selected';} ?>>UT</option>
         <option value="VT" <?php if ($state == 'VT') {print 'selected';} ?>>VT</option>
         <option value="VA" <?php if ($state == 'VA') {print 'selected';} ?>>VA</option>
         <option value="WA" <?php if ($state == 'WA') {print 'selected';} ?>>WA</option>
         <option value="WV" <?php if ($state == 'WV') {print 'selected';} ?>>WV</option>
         <option value="WI" <?php if ($state == 'WI') {print 'selected';} ?>>WI</option>
         <option value="WY" <?php if ($state == 'WY') {print 'selected';} ?>>WY</option>
        </select></td>
       <td><label for="zipcode">Zipcode</label></td>
       <td><input type="text" name="zipcode" id="zipcode" value="<?php print $zipcode ?>" size="5" maxlength="5"></td>
      </tr>
      <tr>
       <td><label for="phone">Phone Number</label></td>
       <td><input type="text" name="phone" id="phone" value="<?php print $phone ?>" size="10" maxlength="10"></td>
       <td><label for="email">Email Address</label></td>
       <td colspan="3"><input type="text" name="email" id="email" value="<?php print $email ?>" size="30" maxlength="50"></td>
      </tr>
      <tr>
       <td><label for="profession">Profession</label></td>
       <td><input type="text" name="profession" id="profession" value="<?php print $profession ?>" size="30" maxlength="50"></td>
       <td><label for="skills">Special Skills</label></td>
       <td colspan="3"><input type="text" name="skills" id="skills" value="<?php print $skills ?>" size="30" maxlength="50"></td>
      </tr>
     </table>
    </fieldset>
    <fieldset>
     <legend>Additional Family Members</legend>
      <table>
       <tr>
        <td colspan="3"><p>Additional family members for family memberships:</p></td>
       </tr>
       <tr>
        <td align="left"><label for="family_fname1">First Name</label></td>
        <td align="left"><label for="family_lname1">Last Name</label></td>
        <td align="left"><label for="family_relationship1">Relationship</label></td>
       </tr>
       <tr>
        <td align="left"><input type="text" name="family_fname1" id="family_fname1" value="<?php print $family_fname1 ?>" size="30" maxlength="50"></td>
        <td align="left"><input type="text" name="family_lname1" id="family_lname1" value="<?php print $family_lname1 ?>" size="30" maxlength="50"></td>
        <td align="left"><select name="family_relationship1" id="relationship1">      
         <option value="" <?php if ($family_relationship1 == '') {print 'selected';} ?>>- Select One -
         <option value="spouse" <?php if ($family_relationship1 == 'spouse') {print 'selected';} ?>>Spouse/Partner</option>
         <option value="child" <?php if ($family_relationship1 == 'child') {print 'selected';} ?>>Child</option>
         </select>
        </td>
       </tr>
       <tr>
        <td align="left"><input type="text" name="family_fname2" id="family_fname2" value="<?php print $family_fname2 ?>" size="30" maxlength="50"></td>
        <td align="left"><input type="text" name="family_lname2" id="family_lname2" value="<?php print $family_lname2 ?>" size="30" maxlength="50"></td>
        <td align="left"><select name="family_relationship2" id="relationship2">      
         <option value="" <?php if ($family_relationship2 == '') {print 'selected';} ?>>- Select One -
         <option value="spouse" <?php if ($family_relationship2 == 'spouse') {print 'selected';} ?>>Spouse/Partner</option>
         <option value="child" <?php if ($family_relationship2 == 'child') {print 'selected';} ?>>Child</option>
         </select>
        </td>
       </tr>
       <tr>
        <td align="left"><input type="text" name="family_fname3" id="family_fname3" value="<?php print $family_fname3 ?>" size="30" maxlength="50"></td>
        <td align="left"><input type="text" name="family_lname3" id="family_lname3" value="<?php print $family_lname3 ?>" size="30" maxlength="50"></td>
        <td align="left"><select name="family_relationship3" id="relationship3">      
         <option value="" <?php if ($family_relationship3 == '') {print 'selected';} ?>>- Select One -
         <option value="spouse" <?php if ($family_relationship3 == 'spouse') {print 'selected';} ?>>Spouse/Partner</option>
         <option value="child" <?php if ($family_relationship3 == 'child') {print 'selected';} ?>>Child</option>
         </select>
        </td>
       </tr>
       <tr>
        <td align="left"><input type="text" name="family_fname4" id="family_fname4" value="<?php print $family_fname4 ?>" size="30" maxlength="50"></td>
        <td align="left"><input type="text" name="family_lname4" id="family_lname4" value="<?php print $family_lname4 ?>" size="30" maxlength="50"></td>
        <td align="left"><select name="family_relationship4" id="relationship4">      
         <option value="" <?php if ($family_relationship4 == '') {print 'selected';} ?>>- Select One -
         <option value="spouse" <?php if ($family_relationship4 == 'spouse') {print 'selected';} ?>>Spouse/Partner</option>
         <option value="child" <?php if ($family_relationship4 == 'child') {print 'selected';} ?>>Child</option>
         </select>
        </td>
       </tr>
       <tr>
        <td align="left"><input type="text" name="family_fname5" id="family_fname5" value="<?php print $family_fname5 ?>" size="30" maxlength="50"></td>
        <td align="left"><input type="text" name="family_lname5" id="family_lname5" value="<?php print $family_lname5 ?>" size="30" maxlength="50"></td>
        <td align="left"><select name="family_relationship5" id="relationship5">      
         <option value="" <?php if ($family_relationship5 == '') {print 'selected';} ?>>- Select One -
         <option value="spouse" <?php if ($family_relationship5 == 'spouse') {print 'selected';} ?>>Spouse/Partner</option>
         <option value="child" <?php if ($family_relationship5 == 'child') {print 'selected';} ?>>Child</option>
         </select>
        </td>
       </tr>
       <tr>
        <td align="left"><input type="text" name="family_fname6" id="family_fname6" value="<?php print $family_fname6 ?>" size="30" maxlength="50"></td>
        <td align="left"><input type="text" name="family_lname6" id="family_lname6" value="<?php print $family_lname6 ?>" size="30" maxlength="50"></td>
        <td align="left"><select name="family_relationship6" id="relationship6">      
         <option value="" <?php if ($family_relationship6 == '') {print 'selected';} ?>>- Select One -
         <option value="spouse" <?php if ($family_relationship6 == 'spouse') {print 'selected';} ?>>Spouse/Partner</option>
         <option value="child" <?php if ($family_relationship6 == 'child') {print 'selected';} ?>>Child</option>
         </select>
        </td>
       </tr>
      </table>
    </fieldset>
    <fieldset>
     <legend>Submit to Database</legend>
     <br>
     <div align="center"><input type="submit" name="submit" id="submit" value="Save">&nbsp;&nbsp;&nbsp;<input type="reset" name="Clear" id="Clear" value="Clear"></div>
    <br><br>
    </fieldset>
    Everything appears to work correctly in the form above. I get the data from the Database, I can properly get it to display in the form, etc....

    The problem that I am having starts at this point....

    Assuming the Member's information has been updated and "form is submitted" it goes to the following PHP Update Script to update the information in the database....

    PHP Code:
    <?php 
    // Open the existing session
    session_start();
    //Test to see if there are post variables to update to the database
    $ID $_POST['ID'];
    print 
    $ID;
    if (
    $ID == "")
    {
    echo 
    "<p>The ID was not captured for the record to be updated.  Update Failed.</p>";
    exit;

    // Set the Database Connection Variables
    $hostname "localhost"// Our DB server.
    $username "XXXXX"// The username for the database.
    $password "XXXXX"// The password for the username above.
    $table "XXXXXXXX"// The name of the table we are working with.
    $dbname "XXXXXX"// This name of the database the table belongs to.
    //Create a variable to manage the database connection
    $dbc MYSQL_CONNECT($hostname$username$password);
    if (!
    $dbc) {
        die(
    'Could not connect: ' mysql_error());
    }
    @
    mysql_select_db"$dbname") or die( "Unable to select database");
     
    //Define the sql udpate query
    mysql_query ("UPDATE ".$table.
    SET application_date='"
    .$_POST['application_date']."' , 
     applicant_fname='"
    .$_POST['applicant_fname']."' , 
     applicant_lname='"
    .$_POST['applicant_lname']."' , 
     street1='"
    .$_POST['street1']."' , 
     street2='"
    .$_POST['street2']."' , 
     city='"
    .$_POST['city']."' , 
     state='"
    .$_POST['state']."' , 
     zipcode='"
    .$_POST['zipcode']."' , 
     phone='"
    .$_POST['phone']."' , 
     email='"
    .$_POST['email']."' , 
     profession='"
    .$_POST['profession']."' , 
     skills='"
    .$_POST['skills']."' , 
     family_fname1='"
    .$_POST['family_fname1']."' , 
     family_lname1='"
    .$_POST['family_lname1']."' , 
     family_relationship1='"
    .$_POST['family_relationship1']."' , 
     family_fname2='"
    .$_POST['family_fname2']."' , 
     family_lname2='"
    .$_POST['family_lname2']."' , 
     family_relationship2='"
    .$_POST['family_relationship2']."' , 
     family_fname3='"
    .$_POST['family_fname3']."' , 
     family_lname3='"
    .$_POST['family_lname3']."' , 
     family_relationship3='"
    .$_POST['family_relationship3']."' , 
     family_fname4='"
    .$_POST['family_fname4']."' , 
     family_lname4='"
    .$_POST['family_lname4']."' , 
     family_relationship4='"
    .$_POST['family_relationship4']."' , 
     family_fname5='"
    .$_POST['family_fname5']."' , 
     family_lname5='"
    .$_POST['family_lname5']."' , 
     family_relationship5='"
    .$_POST['family_relationship5']."' , 
     family_fname6='"
    .$_POST['family_fname6']."' , 
     family_lname6='"
    .$_POST['family_lname6']."' , 
     family_relationship6='"
    .$_POST['family_relationship6']."' , 
     consent_signature='"
    .$_POST['consent_signature']."' , 
     member_bal_prev='"
    .$_POST['member_bal_prev']."' , 
     member_cur_dues='"
    .$_POST['member_cur_dues']."' , 
     member_amt_billed='"
    .$_POST['member_amt_billed']."' , 
     member_amt_paid='"
    .$_POST['member_amt_paid']."' , 
     member_bal_due='"
    .$_POST['member_bal_due']."' , 
     member_status='"
    .$_POST['member_status']."' , 
     member_title='"
    .$_POST['member_title']."' , 
     member_notes='"
    .$_POST['member_notes']."' 
     ID='"
    .$ID."' 
    WHERE ID ='"
    .$ID."' LIMIT 1") or die(mysql_error());  
    // provide a status
    Print "<h2>Record Update Complete</h2>";
    Print 
    "<br><br>";
    // Create a variable from the search term
    $sterm $ID ;
    //If they did not enter a search term we give them an error
    if ($sterm == "")
    {
    echo 
    "<p>There was no record ID passed with the update.  The record update has failed </p>";
    exit;

    //We search the DB for Last Name that was entered and limit the results to 25 
    $data mysql_query(" SELECT `applicant_fname` , `applicant_lname` , `phone` , `email` , `member_status` , `ID` FROM `jos_membership` WHERE `ID` LIKE '$sterm%' LIMIT 0 , 25 ");
    //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 
    "<h3>Sorry, but we can not find an entry to match your query</h3><br>";
    }
    //And we remind them what they searched for
    echo "<br><br>";
    echo 
    "<h3>Your search for \"" $sterm "\" returned " $anymatches " results </h3>";
    echo 
    "<p>A maximum of 25 results are listed below</p>";
    echo 
    "<div align=\"center\"><a href=\"" $_SERVER['HTTP_REFERER'] . "\"> Search Again?</a></div>";
    echo 
    "<br>";
    //Begin building the table to display the results
    print ("<fieldset>" "\n");
    print (
    "<legend>Search Results</legend>" "\n");
    print (
    "<table width=\"100%\">" "\n");
    print (
    "<tr bgcolor=\"#DBDBDB\">" "\n");
    print (
    "<td width=\"*\" align=\"center\"><label>Edit?</label></td>" "\n");
    print (
    "<td width=\"15%\" align=\"center\"><label>First Name</label></td>" "\n");
    print (
    "<td width=\"15%\" align=\"center\"><label>Last Name</label></td>" "\n");
    print (
    "<td width=\"20%\" align=\"center\"><label>Phone</label></td>" "\n");
    print (
    "<td width=\"30%\" align=\"center\"><label>Email</label></td>" "\n");
    print (
    "<td width=\"10%\" align=\"center\"><label>Membership<br>Status</label></td>" "\n");
    print (
    "</tr>" "\n");
    //Now can display the results in a table row
    while($result mysql_fetch_array$data ))
    {
    print (
    "<tr>" "\n");
    print (
    "<td align=\"center\">" "<input type=\"radio\" name=\"member_edit\" id=\"member_edit\" value=\"" $result['ID'] . "\">" "</td>" "\n");
    print (
    "<td>" $result['applicant_fname'] . "</td>" "\n");
    print (
    "<td>" $result['applicant_lname'] . "</td>" "\n");
    print (
    "<td>" $result['phone'] . "</td>" "\n");
    print (
    "<td>" $result['email'] . "</td>" "\n");
    print (
    "<td align=\"center\">" $result['member_status'] . "</td>" "\n");
    print (
    "</tr>" "\n");
    }
    // No more results - End the table
    print ("<tr bgcolor=\"#DBDBDB\"><td colspan=\"6\" align=\"center\">");
    print (
    "<br><input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Edit Selected\"><br>");
    print (
    "</td></tr>");
    print (
    "</table>" "\n");
    print (
    "</fieldset>" "\n"); 
    ?>
    So here is the issue...

    The $ID variable that is displayed on the edit form is not the same $ID variable that arrives at the update form....

    To help illustrate here is an example...

    The ID for Pugh in the Database is "233"
    The ID for Pugh that is displayed on the form edit page is "233"
    The ID that arrives at the Update Script as _POST [ID] is "45"

    Because the ID is not being properly passed, I can not get the data to actually update in the DB.

    To answer your next question, I think the "45" value is the last varaible passed in the _Post Array....

    Also, I do not get any PHP or mysql erros except this one:

    Code:
    45You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ID='45' WHERE ID ='45' LIMIT 1' at line 41
    Any ideas? I have been at this for 2 days now and I just can't seem to crack this nut...

    Thanks,
    Rick
    Thanks,

    Rick

  2. #2
    rickpugh's Avatar
    rickpugh is offline Practically a Glow Sage
    Join Date
    Apr 2005
    Location
    Simi Valley, California, United States
    Posts
    21

    Wink Solved...

    So I was able (after another 3 hours) to figure out my dumb mistake... thought I would post it out here just incase anyone else makes the same dumb mistake...

    Here is what was wrong....

    1. I had the "NAME" and "ID" properties of two different forms fields duplicated. This was causing the last form field with the assigned value to be passed in the _POST array.

    2. I added a hidden form field to contain the Member ID.

    3. The hidden form field had to use the php PRINT function to pass the value, not the php ECHO function...

    Also... just I came across a great short-cut to dump the contents of the _POST array so that I could find out exactly what was being included.... Here is the shortcut:

    PHP Code:
    <?php
    // Open the existing session
    session_start();
    // Dump all from values from the _POST array
    print_r($_POST)
    ?>
    I also wanted to provide the corrected version of the edit and update PHP files incase anyone wants to reuse to help their own efforts...

    Here is the correct EDIT.php file:

    PHP Code:
    <?php 
    // Open the existing session or use the one that is open.
    session_start();
    // Create a variable for the Database ID of the member selected to edit
    $member_edit $_POST['member_edit'];
    //Check to make sure a member was actually selected to edit
    if ($member_edit == "")
    {
    echo 
    "<p>You must select a member before you can edit.  Please use the back button and try again.";
    exit;

    //Now we can connect to the Database
    $hostname "localhost"// Our DB server.
    $username "XXXXXXX"// The username for the database.
    $password "XXXXXXX"// The password for the username above.
    $table "XXXXXXXXXX"// The name of the table we are working with.
    $dbname "XXXXXXXX"// This name of the database the table belongs to.
    MYSQL_CONNECT($hostname$username$password) OR DIE("DB connection unavailable");
    @
    mysql_select_db"$dbname") or die( "Unable to select database");
    //We query the DB for the selected member 
    $query mysql_query("  SELECT `application_date`, `applicant_fname`, `applicant_lname`, `street1`, `street2`, `city`, `state`, `zipcode`, `phone`, `email`, `profession`, `skills`, `membership`, `family_fname1`, `family_lname1`, `family_relationship1`, `family_fname2`, `family_lname2`, `family_relationship2`, `family_fname3`, `family_lname3`, `family_relationship3`, `family_fname4`, `family_lname4`, `family_relationship4`, `family_fname5`, `family_lname5`, `family_relationship5`, `family_fname6`, `family_lname6`, `family_relationship6`, `consent_signature`, `member_bal_prev`, `member_cur_dues`, `member_amt_billed`, `member_amt_paid`, `member_bal_due`, `member_status`, `member_title`, `member_notes`, `ID`
    FROM `jos_membership` WHERE `ID` ='
    $member_edit' LIMIT 0 , 30  ");
    //We build variables for each of the DB Result Values so that we can edit and then update them.
    while ($row = @mysql_fetch_array($query)) {
     
    $application_date $row["application_date"];
     
    $applicant_fname $row["applicant_fname"];
     
    $applicant_lname $row["applicant_lname"];
     
    $street1 $row["street1"];
     
    $street2 $row["street2"];
     
    $city $row["city"];
     
    $state $row["state"];
     
    $zipcode $row["zipcode"];
     
    $phone $row["phone"];
     
    $email $row["email"];
     
    $profession $row["profession"];
     
    $skills $skills["skills"];
     
    $membership $row["membership"];
     
    $family_fname1 $row["family_fname1"];
     
    $family_lname1 $row["family_lname1"];
     
    $family_relationship1 $row["family_relationship1"];
     
    $family_fname2 $row["family_fname2"];
     
    $family_lname2 $row["family_lname2"];
     
    $family_relationship2 $row["family_relationship2"];
     
    $family_fname3 $row["family_fname3"];
     
    $family_lname3 $row["family_lname3"];
     
    $family_relationship3 $row["family_relationship3"];
     
    $family_fname4 $row["family_fname4"];
     
    $family_lname4 $row["family_lname4"];
     
    $family_relationship4 $row["family_relationship4"];
     
    $family_fname5 $row["family_fname5"];
     
    $family_lname5 $row["family_lname5"];
     
    $family_relationship5 $row["family_relationship5"];
     
    $family_fname6 $row["family_fname6"];
     
    $family_lname6 $row["family_lname6"];
     
    $family_relationship6 $row["family_relationship6"];
     
    $consent_signature $row["consent_signature"];
     
    $member_bal_prev $row["member_bal_prev"];
     
    $member_cur_dues $row["member_cur_dues"];
     
    $member_amt_billed $row["member_amt_billed"];
     
    $member_amt_paid $row["member_amt_paid"];
     
    $member_bal_due $row["member_bal_due"];
     
    $member_status $row["member_status"];
     
    $member_title $row["member_title"];
     
    $member_notes $row["member_notes"];
     
    $ID $row["ID"];
    }
    //Check to make sure there is actually data returned to edit
    $anymatches mysql_num_rows($query);
    if (
    $anymatches == 0)
    {
    echo 
    "<h2>No records were returned from the database</h2><br>";
    }
    ?>
    <input type="hidden" name="ID" id="ID" value="<?php print $ID ?>">
    <br /><br />
    <h2>Edit Member Data</h2>
    <br />
    <p>Edit the member's data below and then select "Save".  If you have reached this page in error or do not wish to commit your changes please slect "Cancel"</p>
    <br>
    <fieldset>
     <legend>Member Information</legend>
     <table>
      <tr>
       <td><label for="applicant_fname">First Name</label></td>
       <td><input type="text" name="applicant_fname" id="applicant_fname" value="<?php print $applicant_fname ?>" size="30" maxlength="50"></td>
       <td><label for="applicant_lname">Last Name</label></td>
       <td><input type="text" name="applicant_lname" id="applicant_lname" value="<?php print $applicant_lname ?>"size="30" maxlength="50"></td>
       <td><label for="ID">Member ID:</label></td>
       <td><?php print $ID ?></td>
      </tr>
     </table>
    </fieldset>
    <fieldset>
     <legend>Membership Type</legend>
     <table>
      <tr>
       <td><label for="member_date">Initial Membership Date:</label><br>(YYYY-MM-DD)</td>
       <td><input type="text" name="application_date" id="application_date" value="<?php print $application_date ?>"size="10" maxlength="10"></td>
       <td><label for="member_status">Membership Status:</label></td>
       <td><select name="member_status" id="member_status" size="1">
         <option value="Select One" <?php if ($member_status == '') {print 'selected';} ?>>- Select One -</option>
         <option value="Active" <?php if ($member_status == 'Active') {print 'selected';} ?>>Active</option>
         <option value="Inactive" <?php if ($member_status == 'Inactive') {print 'selected';} ?>>Inactive</option>
         <option value="Suspended" <?php if ($member_status == 'Suspended') {print 'selected';} ?>>Suspended</option>
         </select></td>
      </tr>
      <tr>
       <td><label for="membership_type">Membership Type:</label>
       <td><?php print $membership ?><input type="hidden" name="membership" id="membership" value="<?php print $membership ?>"></td>
       <td><label for="member_title">VCFPA Officer Title:</label></td>
       <td><select name="member_title" id="member_title" size="1">
         <option value="Select One" <?php if ($member_title == '') {print 'selected';} ?>>- Select One -</option>
         <option value="President" <?php if ($member_title == 'President') {print 'selected';} ?>>President</option>
         <option value="Vice President" <?php if ($member_title == 'Vice President') {print 'selected';} ?>>Vice President</option>
         <option value="Treasurer" <?php if ($member_title == 'Treasurer') {print 'selected';} ?>>Treasurer</option>
         <option value="Secretary" <?php if ($member_title == 'Secretary') {print 'selected';} ?>>Secretary</option>
         <option value="Director" <?php if ($member_title == 'Director') {print 'selected';} ?>>Director</option>
         <option value="Chairmanship" <?php if ($member_title == 'Chairmanship') {print 'selected';} ?>>Chairmanship</option>
         <option value="Membership Coordinator" <?php if ($member_title == 'Membership Coordinator') {print 'selected';} ?>>Membership Coordinator</option>
         <option value="Webmaster" <?php if ($member_title == 'Webmaster') {print 'selected';} ?>>Web and Technology</option>
        </select></td>
      </tr>
      <tr>
       <td align="left" colspan="4"><label for="member_notes">Remarks/Notes:</label></td>
      </tr>
      <tr>
       <td align="left" colspan="4"><textarea cols="75" rows="10" name="member_notes" id="member_notes"><?php print $member_notes ?></textarea></td>
      </tr>
     </table>
    </fieldset>
    <fieldset>
     <legend>Account Information</legend>
     <table>
      <tr>
       <td><label for="member_bal_prev">Previous Balance:</label></td>
       <td>$<input type="text" name="member_bal_prev" id="member_bal_prev" value="<?php print $member_bal_prev ?>" size="7" maxlength="7"></td>
      </tr>
      <tr>
       <td><label for="member_cur_dues">Current Membership Dues:</label></td>
       <td>$<input type="text" name="member_cur_dues" id="member_cur_dues" value="<?php print $member_cur_dues ?>" size="7" maxlength="7"></td>
      </tr>
      <tr>
       <td><label for="member_amt_billed">Amount Billed:</label></td>
       <td>$<input type="text" name="member_amt_billed" id="member_amt_billed" value="<?php print $member_amt_billed ?>" size="7" maxlength="7"></td>
      </tr>
      <tr>
       <td><label for="member_amt_paid">Amount Paid:</label></td>
       <td>$<input type="text" name="member_amt_paid" id="member_amt_paid" value="<?php print $member_amt_paid ?>" size="7" maxlength="7"></td>
      </tr>
      <tr>
       <td><label for="member_bal_due">Balace Due:</label></td>
       <td>$<input type="text" name="member_bal_due" id="member_bal_due" value="<?php print $member_bal_due ?>" size="7" maxlength="7"></td>
      </tr>
     </table>
    </fieldset>
    <fieldset>
     <legend>Contact Information</legend>
     <table>
      <tr>
       <td><label for="street1">Street Address</label></td>
       <td><input type="text" name="street1" id="street1" value="<?php print $street1 ?>" size="30" maxlength="100"></td>
       <td><label for="street2">Apt/Suite</label></td>
       <td colspan="3"><input type="text" name="street2" id="street2" value="<?php print $street2 ?>" size="10" maxlength="25"></td>
      </tr>
      <tr>
       <td><label for="city">City</label></td>
       <td><input type="text" name="city" id="city" value="<?php print $city ?>" size="30" maxlength="100"></td>
       <td><label for="state">State</label></td>
       <td><select name="state" id="state">      
         <option value="XX" <?php if ($state == '') {print 'selected';} ?>>- Select One -
         <option value="AL" <?php if ($state == 'AL') {print 'selected';} ?>>AL</option>
         <option value="AK" <?php if ($state == 'AK') {print 'selected';} ?>>AK</option>
         <option value="AZ" <?php if ($state == 'AZ') {print 'selected';} ?>>AZ</option>
         <option value="AR" <?php if ($state == 'AR') {print 'selected';} ?>>AR</option>
         <option value="CA" <?php if ($state == 'CA') {print 'selected';} ?>>CA</option>
         <option value="CO" <?php if ($state == 'CO') {print 'selected';} ?>>CO</option>
         <option value="CT" <?php if ($state == 'CT') {print 'selected';} ?>>CT</option>
         <option value="DE" <?php if ($state == 'DE') {print 'selected';} ?>>DE</option>
         <option value="DC" <?php if ($state == 'DC') {print 'selected';} ?>>DC</option>
         <option value="FL" <?php if ($state == 'FL') {print 'selected';} ?>>FL</option>
         <option value="GA" <?php if ($state == 'GA') {print 'selected';} ?>>GA</option>
         <option value="HI" <?php if ($state == 'HI') {print 'selected';} ?>>HI</option>
         <option value="ID" <?php if ($state == 'ID') {print 'selected';} ?>>ID</option>
         <option value="IL" <?php if ($state == 'IL') {print 'selected';} ?>>IL</option>
         <option value="IN" <?php if ($state == 'IN') {print 'selected';} ?>>IN</option>
         <option value="IA" <?php if ($state == 'IA') {print 'selected';} ?>>IA</option>
         <option value="KS" <?php if ($state == 'KS') {print 'selected';} ?>>KS</option>
         <option value="KY" <?php if ($state == 'KY') {print 'selected';} ?>>KY</option>
         <option value="LA" <?php if ($state == 'LA') {print 'selected';} ?>>LA</option>
         <option value="ME" <?php if ($state == 'ME') {print 'selected';} ?>>ME</option>
         <option value="MD" <?php if ($state == 'MD') {print 'selected';} ?>>MD</option>
         <option value="MA" <?php if ($state == 'MA') {print 'selected';} ?>>MA</option>
         <option value="MI" <?php if ($state == 'MI') {print 'selected';} ?>>MI</option>
         <option value="MN" <?php if ($state == 'MN') {print 'selected';} ?>>MN</option>
         <option value="MS" <?php if ($state == 'MS') {print 'selected';} ?>>MS</option>
         <option value="MO" <?php if ($state == 'MO') {print 'selected';} ?>>MO</option>
         <option value="MT" <?php if ($state == 'MT') {print 'selected';} ?>>MT</option>
         <option value="NE" <?php if ($state == 'NE') {print 'selected';} ?>>NE</option>
         <option value="NV" <?php if ($state == 'NV') {print 'selected';} ?>>NV</option>
         <option value="NH" <?php if ($state == 'NH') {print 'selected';} ?>>NH</option>
         <option value="NJ" <?php if ($state == 'NJ') {print 'selected';} ?>>NJ</option>
         <option value="NM" <?php if ($state == 'NM') {print 'selected';} ?>>NM</option>
         <option value="NY" <?php if ($state == 'NY') {print 'selected';} ?>>NY</option>
         <option value="NC" <?php if ($state == 'NC') {print 'selected';} ?>>NC</option>
         <option value="ND" <?php if ($state == 'ND') {print 'selected';} ?>>ND</option>
         <option value="OH" <?php if ($state == 'OH') {print 'selected';} ?>>OH</option>
         <option value="OK" <?php if ($state == 'OK') {print 'selected';} ?>>OK</option>
         <option value="OR" <?php if ($state == 'OR') {print 'selected';} ?>>OR</option>
         <option value="PA" <?php if ($state == 'PA') {print 'selected';} ?>>PA</option>
         <option value="RI" <?php if ($state == 'RI') {print 'selected';} ?>>RI</option>
         <option value="SC" <?php if ($state == 'SC') {print 'selected';} ?>>SC</option>
         <option value="SD" <?php if ($state == 'SD') {print 'selected';} ?>>SD</option>
         <option value="TN" <?php if ($state == 'TN') {print 'selected';} ?>>TN</option>
         <option value="TX" <?php if ($state == 'TX') {print 'selected';} ?>>TX</option>
         <option value="UT" <?php if ($state == 'UT') {print 'selected';} ?>>UT</option>
         <option value="VT" <?php if ($state == 'VT') {print 'selected';} ?>>VT</option>
         <option value="VA" <?php if ($state == 'VA') {print 'selected';} ?>>VA</option>
         <option value="WA" <?php if ($state == 'WA') {print 'selected';} ?>>WA</option>
         <option value="WV" <?php if ($state == 'WV') {print 'selected';} ?>>WV</option>
         <option value="WI" <?php if ($state == 'WI') {print 'selected';} ?>>WI</option>
         <option value="WY" <?php if ($state == 'WY') {print 'selected';} ?>>WY</option>
        </select></td>
       <td><label for="zipcode">Zipcode</label></td>
       <td><input type="text" name="zipcode" id="zipcode" value="<?php print $zipcode ?>" size="5" maxlength="5"></td>
      </tr>
      <tr>
       <td><label for="phone">Phone Number</label></td>
       <td><input type="text" name="phone" id="phone" value="<?php print $phone ?>" size="10" maxlength="10"></td>
       <td><label for="email">Email Address</label></td>
       <td colspan="3"><input type="text" name="email" id="email" value="<?php print $email ?>" size="30" maxlength="50"></td>
      </tr>
      <tr>
       <td><label for="profession">Profession</label></td>
       <td><input type="text" name="profession" id="profession" value="<?php print $profession ?>" size="30" maxlength="50"></td>
       <td><label for="skills">Special Skills</label></td>
       <td colspan="3"><input type="text" name="skills" id="skills" value="<?php print $skills ?>" size="30" maxlength="50"></td>
      </tr>
     </table>
    </fieldset>
    <fieldset>
     <legend>Additional Family Members</legend>
      <table>
       <tr>
        <td colspan="3"><p>Additional family members for family memberships:</p></td>
       </tr>
       <tr>
        <td align="left"><label for="family_fname1">First Name</label></td>
        <td align="left"><label for="family_lname1">Last Name</label></td>
        <td align="left"><label for="family_relationship1">Relationship</label></td>
       </tr>
       <tr>
        <td align="left"><input type="text" name="family_fname1" id="family_fname1" value="<?php print $family_fname1 ?>" size="30" maxlength="50"></td>
        <td align="left"><input type="text" name="family_lname1" id="family_lname1" value="<?php print $family_lname1 ?>" size="30" maxlength="50"></td>
        <td align="left"><select name="family_relationship1" id="relationship1">      
         <option value="" <?php if ($family_relationship1 == '') {print 'selected';} ?>>- Select One -
         <option value="spouse" <?php if ($family_relationship1 == 'spouse') {print 'selected';} ?>>Spouse/Partner</option>
         <option value="child" <?php if ($family_relationship1 == 'child') {print 'selected';} ?>>Child</option>
         </select>
        </td>
       </tr>
       <tr>
        <td align="left"><input type="text" name="family_fname2" id="family_fname2" value="<?php print $family_fname2 ?>" size="30" maxlength="50"></td>
        <td align="left"><input type="text" name="family_lname2" id="family_lname2" value="<?php print $family_lname2 ?>" size="30" maxlength="50"></td>
        <td align="left"><select name="family_relationship2" id="relationship2">      
         <option value="" <?php if ($family_relationship2 == '') {print 'selected';} ?>>- Select One -
         <option value="spouse" <?php if ($family_relationship2 == 'spouse') {print 'selected';} ?>>Spouse/Partner</option>
         <option value="child" <?php if ($family_relationship2 == 'child') {print 'selected';} ?>>Child</option>
         </select>
        </td>
       </tr>
       <tr>
        <td align="left"><input type="text" name="family_fname3" id="family_fname3" value="<?php print $family_fname3 ?>" size="30" maxlength="50"></td>
        <td align="left"><input type="text" name="family_lname3" id="family_lname3" value="<?php print $family_lname3 ?>" size="30" maxlength="50"></td>
        <td align="left"><select name="family_relationship3" id="relationship3">      
         <option value="" <?php if ($family_relationship3 == '') {print 'selected';} ?>>- Select One -
         <option value="spouse" <?php if ($family_relationship3 == 'spouse') {print 'selected';} ?>>Spouse/Partner</option>
         <option value="child" <?php if ($family_relationship3 == 'child') {print 'selected';} ?>>Child</option>
         </select>
        </td>
       </tr>
       <tr>
        <td align="left"><input type="text" name="family_fname4" id="family_fname4" value="<?php print $family_fname4 ?>" size="30" maxlength="50"></td>
        <td align="left"><input type="text" name="family_lname4" id="family_lname4" value="<?php print $family_lname4 ?>" size="30" maxlength="50"></td>
        <td align="left"><select name="family_relationship4" id="relationship4">      
         <option value="" <?php if ($family_relationship4 == '') {print 'selected';} ?>>- Select One -
         <option value="spouse" <?php if ($family_relationship4 == 'spouse') {print 'selected';} ?>>Spouse/Partner</option>
         <option value="child" <?php if ($family_relationship4 == 'child') {print 'selected';} ?>>Child</option>
         </select>
        </td>
       </tr>
       <tr>
        <td align="left"><input type="text" name="family_fname5" id="family_fname5" value="<?php print $family_fname5 ?>" size="30" maxlength="50"></td>
        <td align="left"><input type="text" name="family_lname5" id="family_lname5" value="<?php print $family_lname5 ?>" size="30" maxlength="50"></td>
        <td align="left"><select name="family_relationship5" id="relationship5">      
         <option value="" <?php if ($family_relationship5 == '') {print 'selected';} ?>>- Select One -
         <option value="spouse" <?php if ($family_relationship5 == 'spouse') {print 'selected';} ?>>Spouse/Partner</option>
         <option value="child" <?php if ($family_relationship5 == 'child') {print 'selected';} ?>>Child</option>
         </select>
        </td>
       </tr>
       <tr>
        <td align="left"><input type="text" name="family_fname6" id="family_fname6" value="<?php print $family_fname6 ?>" size="30" maxlength="50"></td>
        <td align="left"><input type="text" name="family_lname6" id="family_lname6" value="<?php print $family_lname6 ?>" size="30" maxlength="50"></td>
        <td align="left"><select name="family_relationship6" id="relationship6">      
         <option value="" <?php if ($family_relationship6 == '') {print 'selected';} ?>>- Select One -
         <option value="spouse" <?php if ($family_relationship6 == 'spouse') {print 'selected';} ?>>Spouse/Partner</option>
         <option value="child" <?php if ($family_relationship6 == 'child') {print 'selected';} ?>>Child</option>
         </select>
        </td>
       </tr>
      </table>
    </fieldset>
    <fieldset>
     <legend>Submit to Database</legend>
     <br>
     <div align="center"><input type="submit" name="submit" id="submit" value="Save">&nbsp;&nbsp;&nbsp;<input type="reset" name="Clear" id="Clear" value="Clear"></div>
    <br><br>
    </fieldset>
    Here is the correct UPDATE.php file:

    PHP Code:
    <?php 
    // Open the existing session or use the one that is open.
    session_start();
    // Create a variable for the Database ID of the member selected to edit
    $ID $_POST['ID'];
    //Check to make sure a member was actually selected to edit
    if ($ID == "")
    {
    echo 
    "<p>No ID has been passed to update the record in the database.  Please check the form and try again.";
    exit;

    //Now we can connect to the Database
    // Set the Database Connection Variables
    $hostname "localhost"// Our DB server.
    $username "XXXXXXX"// The username for the database.
    $password "XXXXXXX"// The password for the username above.
    $table "XXXXXXXXXX"// The name of the table we are working with.
    $dbname "XXXXXXXX"// This name of the database the table belongs to.
    //Create a variable to manage the database connection
    $dbc MYSQL_CONNECT($hostname$username$password);
    if (!
    $dbc) {
        die(
    'Could not connect: ' mysql_error());
    }
    @
    mysql_select_db"$dbname") or die( "Unable to select database");
    //Define the sql udpate query
    mysql_query ("UPDATE ".$table.
    SET application_date='"
    .$_POST['application_date']."' , 
     applicant_fname='"
    .$_POST['applicant_fname']."' , 
     applicant_lname='"
    .$_POST['applicant_lname']."' , 
     street1='"
    .$_POST['street1']."' , 
     street2='"
    .$_POST['street2']."' , 
     city='"
    .$_POST['city']."' , 
     state='"
    .$_POST['state']."' , 
     zipcode='"
    .$_POST['zipcode']."' , 
     phone='"
    .$_POST['phone']."' , 
     email='"
    .$_POST['email']."' , 
     profession='"
    .$_POST['profession']."' , 
     skills='"
    .$_POST['skills']."' , 
     family_fname1='"
    .$_POST['family_fname1']."' , 
     family_lname1='"
    .$_POST['family_lname1']."' , 
     family_relationship1='"
    .$_POST['family_relationship1']."' , 
     family_fname2='"
    .$_POST['family_fname2']."' , 
     family_lname2='"
    .$_POST['family_lname2']."' , 
     family_relationship2='"
    .$_POST['family_relationship2']."' , 
     family_fname3='"
    .$_POST['family_fname3']."' , 
     family_lname3='"
    .$_POST['family_lname3']."' , 
     family_relationship3='"
    .$_POST['family_relationship3']."' , 
     family_fname4='"
    .$_POST['family_fname4']."' , 
     family_lname4='"
    .$_POST['family_lname4']."' , 
     family_relationship4='"
    .$_POST['family_relationship4']."' , 
     family_fname5='"
    .$_POST['family_fname5']."' , 
     family_lname5='"
    .$_POST['family_lname5']."' , 
     family_relationship5='"
    .$_POST['family_relationship5']."' , 
     family_fname6='"
    .$_POST['family_fname6']."' , 
     family_lname6='"
    .$_POST['family_lname6']."' , 
     family_relationship6='"
    .$_POST['family_relationship6']."' , 
     consent_signature='"
    .$_POST['consent_signature']."' , 
     member_bal_prev='"
    .$_POST['member_bal_prev']."' , 
     member_cur_dues='"
    .$_POST['member_cur_dues']."' , 
     member_amt_billed='"
    .$_POST['member_amt_billed']."' , 
     member_amt_paid='"
    .$_POST['member_amt_paid']."' , 
     member_bal_due='"
    .$_POST['member_bal_due']."' , 
     member_status='"
    .$_POST['member_status']."' , 
     member_title='"
    .$_POST['member_title']."' , 
     member_notes='"
    .$_POST['member_notes']."' ,
     ID='"
    .$_POST['ID']."' 
    WHERE ID ='"
    .$ID."' LIMIT 1") or die(mysql_error());  
    Print 
    "<br><br>";
    //If they did not enter a search term we give them an error
    if ($ID == "")
    {
    echo 
    "<p>There was no ID Passed to verify your updated informaiton.  The record update has failed </p>";
    exit;

    //We search the DB for Last Name that was entered and limit the results to 25 
    $data mysql_query(" SELECT `applicant_fname` , `applicant_lname` , `phone` , `email` , `member_status` , `ID` FROM `jos_membership` WHERE `ID` LIKE '$ID' LIMIT 0 , 25 ");
    //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 
    "<h3>Sorry, but we can not find an entry to match your query</h3><br>";
    }
    //And we remind them what they searched for
    echo "<br><br>";
    echo 
    "<h3>Your search for \"" $ID "\" returned " $anymatches " results </h3>";
    echo 
    "<p>A maximum of 25 results are listed below</p>";
    echo 
    "<div align=\"center\"><a href=\"" $_SERVER['HTTP_REFERER'] . "\"> Search Again?</a></div>";
    echo 
    "<br>";
    //Begin building the table to display the results
    print ("<fieldset>" "\n");
    print (
    "<legend>Search Results</legend>" "\n");
    print (
    "<table width=\"100%\">" "\n");
    print (
    "<tr bgcolor=\"#DBDBDB\">" "\n");
    print (
    "<td width=\"*\" align=\"center\"><label>Edit?</label></td>" "\n");
    print (
    "<td width=\"15%\" align=\"center\"><label>First Name</label></td>" "\n");
    print (
    "<td width=\"15%\" align=\"center\"><label>Last Name</label></td>" "\n");
    print (
    "<td width=\"20%\" align=\"center\"><label>Phone</label></td>" "\n");
    print (
    "<td width=\"30%\" align=\"center\"><label>Email</label></td>" "\n");
    print (
    "<td width=\"10%\" align=\"center\"><label>Membership<br>Status</label></td>" "\n");
    print (
    "</tr>" "\n");
    //Now can display the results in a table row
    while($result mysql_fetch_array$data ))
    {
    print (
    "<tr>" "\n");
    print (
    "<td align=\"center\">" "<input type=\"radio\" name=\"member_edit\" id=\"member_edit\" value=\"" $result['ID'] . "\">" "</td>" "\n");
    print (
    "<td>" $result['applicant_fname'] . "</td>" "\n");
    print (
    "<td>" $result['applicant_lname'] . "</td>" "\n");
    print (
    "<td>" $result['phone'] . "</td>" "\n");
    print (
    "<td>" $result['email'] . "</td>" "\n");
    print (
    "<td align=\"center\">" $result['member_status'] . "</td>" "\n");
    print (
    "</tr>" "\n");
    }
    // No more results - End the table
    print ("<tr bgcolor=\"#DBDBDB\"><td colspan=\"6\" align=\"center\">");
    print (
    "<br><input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Edit Selected\"><br>");
    print (
    "</td></tr>");
    print (
    "</table>" "\n");
    print (
    "</fieldset>" "\n"); 
    ?>
    Thanks,

    Rick

  3. #3
    David I is offline Newbie
    Join Date
    Jun 2010
    Posts
    1,245

    Default

    Hello Rickpugh,

    We are glad that you managed to handle this.

Similar Threads

  1. Capturing Form Data in a MySQL Databse
    By QHF in forum General Support
    Replies: 12
    Last Post: 10-01-2007, 09:22 PM
  2. PHP 5.1 and MySQL 4.1
    By Raven in forum WHM, Resellers, VPS and Dedicated Hosting Topics
    Replies: 11
    Last Post: 08-13-2006, 11:57 AM
  3. Replies: 0
    Last Post: 04-21-2005, 09:13 PM
  4. Replies: 0
    Last Post: 04-21-2005, 09:13 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14