refresh page after changing nick name
Posted: Wed Dec 15, 2010 9:20 am
hi all, i've only just began learning php and im a bit stuck on this. i have a page where the user can change his name on his profile, the page should refresh and display his new name in the text box but it isnt doing it, however it is changing the name in the databse but is only showed the change next time i log in.
Code: Select all
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<div class="content">
<table class="tform">
<col class="col_first" />
<col class="col_second" />
<tbody>
<tr>
<td><label>Screen name:</label></td>
<td><input type="text" class="text" name="nick_name" id="profile_name" value=" <?php echo $_SESSION['SESS_NICK_NAME'];?> " /></td>
</tr>
<tr>
<td></td>
<td class="tleft">
<button class="blue" type="submit" name="change_name">Save Changes</button>
</td>
</tr>
</tbody>
</table>
</div>
</form>
</div>
<?php
if(isset($_POST['change_name']))
{
$name = $_POST['nick_name'];
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}
$qry = "UPDATE `tmp`.`members` SET `firstname` = '" . $name . "' WHERE `members`.`member_id` =" . $_SESSION['SESS_MEMBER_ID'] . ";";
$result = @mysql_query($qry);
//Check whether the query was successful or not
if(!$result) {
die("Query failed");
}
$msg = "You have changed you're name to " . $name;
echo "<script langauge=\"javascript\">alert(\"".$msg."\");</script>";
echo "<META HTTP-EQUIV=refresh CONTENT=15>";
}
?>