Jump to content

Recommended Posts

hey guys

i have edit profile page for the user

the issue is that

some of the values use <select>

and when the user refreshes the page

the <select> box changes back to the first value

and instead i want it too stay on the select value

here is the code



$id = $_SESSION['userid'];
if (isset($_SESSION['userid'])) {
$sql = mysql_query("SELECT * FROM users WHERE userid = '{$id}'") or die(mysql_error());
$r=mysql_fetch_array($sql);
$knickname = $_POST['nickname'];
$state = $_POST['state'];
$age = $_POST['age'];
$email = $_POST['email'];
$country = $_POST['country'];
$states = file("states.txt");
sort($states);
if ($_POST['submit']) {
$result = mysql_query("UPDATE users SET  `knickname` =  '$knickname', `age` =  '$age', `email` =  '$email', `state` = '$state', `country` = '$country'  WHERE  userid = '$id'") or die(mysql_error());
header ("Refresh:2");
echo "Your profile has been Updated<br>";
} else {
?>
<form method="POST">
Knickname: <input name="nickname" type="text" value="<? echo $r['knickname']; ?>"><br>
Age: 
<select name="age">
<?
for ($i = 1; $i < 105; $i++) {
echo "<option>". $i ."</option>";
}
?>
</select>
Current age <? echo $r['age']; ?><br>
State: 
<select name="state">
<?
foreach ($states as $state) {
echo "<option>". $state ."</option>";
}
?>
</select><br>
Country: <input name="country" type="text" value="<? echo $r['country']; ?>"><br>
Email: <input name="email" type="text" value="<? echo $r['email']; ?>"><br>
<input type="submit" name="submit" value="Submit">
</form>
<?
}
} else {
header ("Location:index.php?action=login&message=login");
}

any ideas

Link to comment
https://forums.phpfreaks.com/topic/55445-selected-help/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.