Xeven Posted March 7, 2008 Share Posted March 7, 2008 Ok so I have a form that is working all fine. But now im getting into the "fine tuning" stuff and want to make it a lot more user friendly. Basically this form is going to be used to update the logged in users details. So there will be four fields viewable: Firstname, Lastname, Password and Confirm Password. What I am trying to get happening is, when the page is loaded I would like the Firstname and Lastname to be populated with the user's details. Now because there is a session being held on the page it should be possible to pull this data from the database right? This is what my code looks like, I don't seem to get any errors, but the fields just don't populate <p><form id="cpupdate" name="update" method="POST" action="update.php"> <?php include ("info.inc"); $connect = mysql_connect($host,$account,$password); $db = mysql_select_db("database",$connect) or die("Can't connect to database"); $sql = "SELECT * FROM user WHERE user_id = '".$_SESSION['sessioname']."'"; $result = mysql_query($sql,$connect) or die (mysql_error()); $row=mysql_fetch_array($result); { $firstname = $row['firstName']; $lastname = $row['lastName']; } ?> <label> <div align="left">First Name</div> <div align="left"> <input type="text" value="<?php echo $firstname;?>" maxlength="25" name="firstname" id="firstname" title="Enter your first name"/> I really hope I am not overlooking something that is pretty obvious. I thought I was just about getting the hang of this. Thanks Quote Link to comment Share on other sites More sharing options...
deadonarrival Posted March 7, 2008 Share Posted March 7, 2008 $row=mysql_fetch_array($result); try $row=mysql_fetch_assoc($result); I thought mysql_fetch_array() needed 2 arguments? I might be out of date though, never use it. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted March 7, 2008 Share Posted March 7, 2008 "I thought mysql_fetch_array() needed 2 arguments?" no, i always use it. i would echo $sql and see what the query looks like. Quote Link to comment Share on other sites More sharing options...
deadonarrival Posted March 7, 2008 Share Posted March 7, 2008 Couple of checks In your mysql, are the field names firstName and lastName, with capital N's (not sure if this makes a difference) For $sql = "SELECT * FROM user WHERE user_id = '".$_SESSION['sessioname']."'"; Try $sql = "SELECT * FROM `user` WHERE `user_id` = '{$_SESSION['sessioname']}'"; Just in case something is wrong with the query (although it looked okay) print $_SESSION['sessioname']; for me Just noticed this!!! Should that be sessioName or sessioNName? How many N's? Quote Link to comment Share on other sites More sharing options...
Xeven Posted March 8, 2008 Author Share Posted March 8, 2008 Hey guys, thanks for all your help on this. It all helped and made me realise where I had gone wrong. It must have been pretty late last night. Well the problem was right here $sql = "SELECT * FROM user WHERE user_id = '".$_SESSION['sessioname']."'"; It wasn't supposed to be looking at the user_id but was supposed to be looking at another field called email! I feel like such an idiot after finally working it out. But thanks to all that helped, without it I probably would not have realised what I did wrong. Quote Link to comment Share on other sites More sharing options...
deadonarrival Posted March 8, 2008 Share Posted March 8, 2008 Sometimes you just have to sit there and go through it literally word by word... if you just read it through you see what you want to see. "Select the info, that's right, display it, that's right... so where did I go wrong" Instead you might have to break problems down into "Right, so I" Query the database for x fields by y condition. Do zz to the field Print y field. If you write it down, you might notice where it doesn't follow your plan (assuming you plan your functions, a basic layout of what you want to do with the function goes a long way) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.