SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Nov 2012
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    auto filling form

    ellow. how i can auto fill the form for address and else.i just know how to auto fill the username because it is using the echo from session login username.can someone help me ? here is the code
    Code:
    <?php
    error_reporting(E_ALL);
    session_start(); 
    if(!isset($_SESSION['MM_Username'])) {
    echo "You are not logged in or registered / Click <a href='login.php'>Here</a> to login !";
    } else {
    ?>
    
    <style type="text/css">
    <!--
    body { background:#000; background-attachment:fixed; background-repeat:no-repeat; color:#fff; font-family:"Trebuchet MS", Arial, Helvetica, sans-serif; }
    table { background:#000; border:1px solid white;}
    -->
    </style>
    </head>
    
    
    <body>
    <p><b>Welcome <?PHP echo $_SESSION['MM_Username']; ?> !</b></p>
    <form name="form1" method="post" action="order_product_process.php">
      <p align="center" class="style10">&nbsp;</p>
      <p align="center" class="style10">&nbsp;</p>
      <p align="center" class="style10">&nbsp;</p>
      <p align="center" class="style10">&nbsp;</p>
      <p align="center" class="style10">Order Form:</p>
      <div align="center">
            <table width="500" >
              <tr>
                    <td width="239">Username</td>
                <td width="249">
                <input name="username" type="text" id="username" value="<?PHP echo $_SESSION['MM_Username']; ?>" readonly="true"></td> 
              </tr>
              <tr>
                    <td>Address</td>
                <td><textarea name="address" id="address"></textarea></td>
              
              </tr>
              <tr>
                    <td>Phone</td>
                    <td><input name="phone" type="text" id="phone" maxlength="30"></td>
              </tr>
              <tr>
                    <td>IC Number</td>
                    <td><input name="ic" type="text" id="ic" maxlength="30"></td>
              </tr>
              <tr>
                    <td>Product Name</td>
                    <td><input name="product_name" type="text" id="product_name" maxlength="30"></td>
              </tr>
              <tr>
                    <td>Quantity</td>
                    <td>      <input name="quantity" type="text" id="quantity" maxlength="30"></td>
              </tr>
              <tr>
                    <td>&nbsp;</td>
                    <td><input type="submit" name="Submit" value="Order">     <input name="Reset" type="reset" id="Reset" value="Reset"></td>
              </tr>
            </table>
      </div>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
    </form>
    </body>
    </html>
    <?php } ?>

  2. #2
    SitePoint Member VSDan's Avatar
    Join Date
    Feb 2004
    Location
    Vancouver, BC, Canada
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Auto-fill from where?

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I paresume that the username is also stored in a database table along with the addresses. So query the database table using that username (username must be a unique one, otherwise there should be some user_id in the session as well). Do something like this:
    PHP Code:
    $result mysql_query("SELECT * FROM tblename WHERE username='" $_SESSION['MM_Username'] .  "'") or die(mysql_error()); 
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  4. #4
    SitePoint Member VSDan's Avatar
    Join Date
    Feb 2004
    Location
    Vancouver, BC, Canada
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If the case, to add to that:

    If address stored in field called 'address', then:

    unset($address);
    if ($result) { $address = @mysql_result($result, 0, 'address'); }

    <textarea name="address" id="address"><?php echo $address; ?></textarea>

    NOTE: clean $_SESSION['MM_Username'] first before use in mySQL statement to prevent possibility of SQL injections.


Bookmarks

Posting Permissions

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