Jump to content

selected help


quickstopman

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.