I am trying to create a page where a registered user can go, view the information from their profile, and update that information if necessary. I've started putting something together however it's inefficient in my opinion. Here's what I'm trying to figure out:
- Is there a way to check if a change has occurred in each field before it updates the DB? It seems to me that there's no need to update everything when maybe only 1-2 items has changed.
- I have a state drop down box which is created from the DB. I currently have it set to select the state the user registered with - but it's creating a duplicate value in the list. For example, let's say I registered in VA, then I go to update my profile. The state selected is VA but then on the drop down list VA appears a second time. Is there anyway to prevent this duplication? I enclosed the code I'm using below.
- Is there a better way to store User Variables then in Sessions? Currently I am setting the following variables in the Session: First Name (FName), User ID (UserID), Username (Username).
<?PHP
include 'dbconnection.php';
$query = "Select Code,Description FROM cd_states";
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
echo("<option select value =\"$Array[7]\">$Array[8]</option>");
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_row($result)) {
echo("<option value=\"$row[0]\">$row[1]</option>");
}
}
else {
echo "No rows found!";
}
mysql_free_result($result);
?>