Member Avatar for megachip04

I have a form in account.php that is prefilled with the user's current info but can be changed and then when you submit, it updates the database. However, when returned to the page after the update, the prefilled text is not updated. It only updates if you re-log in. At this point I have only messed with updating the username.

ACCOUNT.PHP

<div id="main_middle"> 
<h1>&nbsp;
</h1>
<h1>MANAGE YOUR ACCOUNT INFORMATION</h1>
<p>&nbsp;</p>
username :
<form method="post" action="update_check.php">
  <input type="text" name="username" value="<?php echo "".$_SESSION['username'].""; ?>" size="40" />
  <input name="update data" type="submit" id="update data2" value="save changes"/>
</form>
<br />
<p>&nbsp;</p>
email:<br />
<form method="post" action="update_check.php">
<input name="email" type="text" id="email" value="<?php echo "".$_SESSION['email'].""; ?>" size="40" />
<input name="update data" type="submit" id="update data" value="save changes"/>
<br />
<br />
<br />
<input name="reset" type="reset" id="reset" value="reset form"/>
</form>

</div>

I have set up the username session variable to update if the database updates, however, it does not seem to be working correctly. Any suggestions?

UPDATE_CHECK.PHP

<?php

include("db_config.php");

$tbl_name="usernames"; // Table name

// username and password sent from form 
$username=$_POST['username'];

$username = stripslashes($username);
$username = mysql_real_escape_string($username);

$username = $_POST['username'];
$checkformembers = mysql_query("SELECT * FROM email_confirm WHERE username = '$username'");
if(mysql_num_rows($checkformembers) != 0){
header("location:sign_up_usererror.php");
die();
}

$username = $_POST['username'];
$checkformembers = mysql_query("SELECT * FROM usernames WHERE username = '$username'");
if(mysql_num_rows($checkformembers) != 0){
header("location:sign_up_usererror.php");
die();
}

$result = mysql_query("UPDATE usernames SET username = '$username'");

if($result) {
$_SESSION['username'] = $_POST['username'];
header("location:account.php");
die();
}

?>

Recommended Answers

All 4 Replies

right after your beginning php tag, line 2 call session start.

session_start();
Member Avatar for megachip04

wow...:/

thanks for the swift reply!

would it be ok for me to just insert it at the end of the db_config.php that I included in the beginning?

@megachip04 : you must add session_start(); in the first line after php tag. It must be error like this if you put session_start(); after any code.

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at E:\xampp\htdocs\daniweb\session.php:1) in E:\xampp\htdocs\daniweb\session.php on line 2

it should be the first thing on the page after your beginning php tag.

<?php
session_start();
// rest of your code.

otherwise, as leakbali pointed out, if you have output to the page prior to session_start call, you may get a php warning as described above.
you could include it in your db_config code. just put it at the very top of the page.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.