Edit form, data not re-fill

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nuttynibbles
    New Member
    • Sep 2007
    • 7

    #1

    Edit form, data not re-fill

    im doing a edit profile page. the page would pull out data frm mysql and populate the forms respectively.

    user will edit and update their profile. The page would then validate the value in the form. if there's an error, it would prompt the user. when this happen, the form do not retain the newly entered value but instead re-display what is pull out from the database.. how do i retain the newly entered value in the textbox?

    here is my code:[code=php]
    <?php
    //extract customer info
    $query = "SELECT * FROM advertiser_test WHERE status='Enabled ' AND cid='$cid'";
    $result = mysql_query($qu ery,$conn);
    $rs = mysql_fetch_ass oc($result);
    ...
    //process logic

    //update db

    ?>
    <html>
    ..
    <body>
    <input name="txtEmail" type="text" id="txtEmail" value=<?php echo $rs['email']?> >
    </body>
    </html>[/code]

    i understand that the reason is because when the re-page load, it would pull out user info frm mysql n re-display it into the text box.. so is there a way around it?
    Last edited by pbmods; Sep 2 '07, 04:21 PM. Reason: Added CODE tags.
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    I hope you can easily understand the login that I have used in the below code

    [PHP]<?php
    if(submit)
    {
    ...
    //process logic

    if(some error found)
    $retain_submitt ed_value = true;

    //update db
    }

    if($retain_subm itted_value==tr ue)
    {
    $email = $_POST["email"];
    }
    else
    {
    //extract customer info
    $query = "SELECT * FROM advertiser_test WHERE status='Enabled ' AND cid='$cid'";
    $result = mysql_query($qu ery,$conn);
    $rs = mysql_fetch_ass oc($result);
    $email = $rs['email'];
    }

    ?>
    <html>
    ..
    <body>
    <input name="txtEmail" type="text" id="txtEmail" value=<?php echo $email?> >
    </body>
    </html>[/PHP]

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, NuttyNibbles. Welcome to TSDN!

      Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.

      Comment

      • nuttynibbles
        New Member
        • Sep 2007
        • 7

        #4
        Hi mwasif , could u explain ur code.. tks

        Comment

        Working...