Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Aug 2011
    Posts
    134
    Thanks
    20
    Thanked 0 Times in 0 Posts

    auto fill fields from the database

    I have a simple form right now:
    Code:
    <form action='<? echo $PHP_SELF;?>' method='POST'>
    Username:<input type='text' name='username'><br>
    Email:<input type='text' name='email'><br>
    Posts:<input type='text' name='posts'><br>
    Joindate<input type='text' name='join'><br>
     <input type="submit" value="Submit" />
    </form>
    What I need is, when the user fills his username and does one of the following:
    1.presses tab
    2.Presses enter
    3.clicks on a fetch button(fetch button does not exist now,i would like to know how to create it using javascript or anything else that suits my criteria)

    Once he does any of the above it should automatically generate the remaining fields from the database.
    The query would look like this:
    $qry=mysql_query("SELECT * from user where username =`$_POST['username']`");
    $row=mysql_fetch_assoc('$qry);
    echo $row['posts] and so on..

    After it is autogenerated he can edit the fields and submit to update the database fields.

    Please move this post if I am in the wrong forum.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    This cannot be done in PHP. PHP is a server side language, once it is done with its request and sent its response, its job is done and cannot be interacted with without the use of a new request.
    This behaviour you are looking for uses javascript to facility an AJAX communication with the PHP page providing the get/post the same way the standard processing occurs in a PHP page. Same rules apply, PHP returns its results and AJAX handles the new data to refresh an existing page in the background.

  • #3
    Regular Coder
    Join Date
    Aug 2011
    Posts
    134
    Thanks
    20
    Thanked 0 Times in 0 Posts
    Thanks.I am new to AJAX and i am trying to find some code that does something similar so that i can learn how to do it and apply that concept to my code.


  •  

    Posting Permissions

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