auto fill form fields from mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
monkeymafia
Forum Commoner
Posts: 31
Joined: Mon Oct 08, 2007 3:08 pm

auto fill form fields from mysql

Post by monkeymafia »

Hi

*PHP rookie*

ive got a login form barely just working 8O
once the user is logged in they are presented with a form to fill out.
I want the telephone and email fields to be autofilled from the mysql database (customer table).
obviously this must depend on the user thats logged in.

am i on the right lines with this code:

Code: Select all

<?php
// SQL connection goes here
$query = "SELECT * FROM customers";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
?>
then have this code placed in the fields

Code: Select all

value="<?php echo $row['email'] ?>"
but how do i get it to autofill the details of the user who has just logged in.
would appreciate any help, have been trying this for hours with no luck :cry:

here is the url: http://www.kumar.adsl24.co.uk/Storm%20B ... ccount.php

user: testuser
pass: test
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

Well you might want to refactor your code to

Code: Select all

SELECT * FROM customers WHERE customer_id = '[users_id]'";
Also mysql_fetch_assoc() might be a better choice to get your row of data.[/syntax]
Post Reply