Page 1 of 1

auto fill form fields from mysql

Posted: Wed Oct 10, 2007 6:16 pm
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

Posted: Wed Oct 10, 2007 6:40 pm
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]