PHP update help!

I am still quite new to php and mysql but i’ve managed to setup a login system, where a member can register and login to our website. Once they have logged in they can view the secure section of the site and also view their profile. This profile stores the information that relates to the database, ie personal details etc.

I am able to retrieve the data using php and display it in a form using the echo commands but I want my members to be able to update their information if necessary.

I have tried many solutions to no avail. I have started an update script in which once the form is submitted the data is stored successfully into the database but i don’t know how to retrieve that data and display it on the profile page again where they submitted their new information. Hope this all makes sense.

Here is my php code:

<?php // connect to your MySQL database here require_once "config2.php"; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); // the values you want to change to $id = "1"; $fname = $_POST['firstname']; $lname = $_POST['lastname']; $address = $_POST['address']; $address2 = $_POST['address2']; $county = $_POST['county']; $postcode = $_POST['postcode']; $email = $_POST['email']; $telephone = $POST['telephone']; $login = $_POST['login']; // Build sql command to update just one record or "row" $sqlCommand = "UPDATE members SET firstname='$fname', lastname='$lname', address='$address', address2='$address2', county='$county', postcode='$postcode', telephone='$telephone', email='$email', login='$login' WHERE member_id='$id' LIMIT 1"; // Execute the query here now $query = mysql_query($sqlCommand) or die (mysql_error()); // Replace sql command to Select the data now $sqlCommand = "SELECT firstname, lastname, address, address2, county, postcode, email, telephone, login FROM members WHERE member_id='$id' LIMIT 1"; $query = mysql_query($sqlCommand) or die (mysql_error()); ?? ?>

I know the code isn’t the best thought out but it works, just can’t get the information they entered back to the previous form

Any help would be great appreciated )

Sponsor our Newsletter | Privacy Policy | Terms of Service