Jump to content

Recommended Posts

I have a problem with my session i THINK!. When a user logs in to the website, they see an edit link. Once they click the link, a form appears with values from the database echoed into text boxes using the current session variables. Ok, I alter these these values then press edit and the new values get successfully updated into the database table with the new values echoed into another form for show. - This is fine

 

The problem is, i follow the same process a SECOND time, ie press the edit link, alter values, etc and press edit again but the data isnt updated in the database table but the data in the session variables get updated. Why could this be. Would pasting the code be more helpful?

 

The only way to update again is to log out, the re-login >:(.

Link to comment
https://forums.phpfreaks.com/topic/74448-sessions-and-update/
Share on other sites

sorry if this code is too long  :(

 

if (!$_POST['submit']){

$sql = "SELECT * FROM users WHERE username = '$username'"; // Database checks
$result = mysql_query($sql) or die(mysql_error());
$num=mysql_num_rows($result);
$row = mysql_fetch_array($result);

$database_title = $row["title"];
$database_firstname = $row["firstname"];
$database_lastname = $row["lastname"];
$database_address1 = $row["address1"];
$database_address2 = $row["address2"];
$database_city = $row["city"];
$database_postcode = $row["postcode"];
$database_country = $row["country"];
$database_email = $row["email"];


?>
      </p>

<form method="post"  action="<? echo $PHP_SELF?>">

<h3>Enter Details Below</h3>

<fieldset>

<label>
<span><b>Title:</b></span>
<span class="price"><input name="title" type="text" id="title" value="<? echo $_SESSION['title'];?>" size="24" />
</span>
<br><br>
<span><b>First Name:</b></span>
<span class="price"><input name="firstname" type="text" id="firstname" value="<? echo $_SESSION['firstname'];?>" size="24" />
</span>
<br><br>
<span><b>Last Name:</b></span>
<span class="price"><input name="lastname" type="text" id="lastname" value="<? echo $_SESSION['lastname'];?>" size="24" />
</span>
<br><br>
<span><b>Address Line 1:</b></span>
<span class="price"><input name="address1" type="text" id="address1" value="<? echo $_SESSION['address1'];?>" size="24" />
</span>
<br><br>
<span><b>Address Line 2:</b></span>
<span class="price"><input name="address2" type="text" id="address2" value="<? echo $_SESSION['address2'];?>" size="24" />
</span>
<br><br>
<span><b>City/Town:</b></span>
<span class="price"><input name="city" type="text" id="city" value="<? echo $_SESSION['city'];?>" size="24" />
</span>
<br><br>
<span><b>Post Code:</b></span>
<span class="price"><input name="postcode" type="text" id="postcode" value="<? echo $_SESSION['postcode'];?>" size="24" />
</span>
<br><br>
<span><b>Country:</b></span>
<span class="price"><input name="country" type="text" id="country" value="<? echo $_SESSION['country'];?>" size="24" />
</span>
<br><br>
<span><b>Email:</b></span>
<span class="price">
<input name="email" type="text" id="email" value="<? echo $_SESSION['email'];?>" size="24" />
</span>
<br><br><br>
<input name="submit" type="submit" id="submit" value="Edit" />
</fieldset>
</form>
<?
} else {
$sql = "UPDATE users SET title = '$_POST[title]', firstname = '$_POST[firstname]' , lastname = '$_POST[lastname]', address1 = '$_POST[address1]', address2 = '$_POST[address2]', city = '$_POST[city]', postcode = '$_POST[postcode]', country = '$_POST[country]', email = '$_POST[email]' WHERE username = '$_SESSION[username]'";
$result = mysql_query($sql);




$_SESSION['username'] = $_POST['username'];
$_SESSION['password'] =  $_POST['password'];
$_SESSION['title'] =  $_POST['title'];
$_SESSION['firstname'] =  $_POST['firstname'];
$_SESSION['lastname'] =  $_POST['lastname'];
$_SESSION['address1'] =  $_POST['address1'];
$_SESSION['address2'] =  $_POST['address2'];
$_SESSION['city'] =  $_POST['city'];
$_SESSION['postcode'] =  $_POST['postcode'];
$_SESSION['country'] =  $_POST['country'];
$_SESSION['email'] =  $_POST['email'];
$_SESSION['logged_in'] = 1;


echo "<br><br>";	
echo "<form>";
echo "<h3>Details Successfully Updated</h3>";
echo "<fieldset>";
echo "<label>";
echo "<span><b>Title:</b></span>";
echo "<span class='price'><input name='title' type='text' id='title' value='$_SESSION[title]' size='24' />";
echo "</span>";
echo "<br><br>";
echo "<span><b>First Name:</b></span>";
echo "<span class='price'><input name='firstname' type='text' id='firstname' value='$_SESSION[firstname]' size='24' />";
echo "</span>";
echo "<br><br>";
echo "<span><b>Last Name:</b></span>";
echo "<span class='price'><input name='lastname' type='text' id='lastname' value='$_SESSION[lastname]' size='24' />";
echo "</span>";
echo "<br><br>";
echo "<span><b>Address Line 1:</b></span>";
echo "<span class='price'><input name='address1' type='text' id='address1' value='$_SESSION[address1]' size='24' />";
echo "</span>";
echo "<br><br>";
echo "<span><b>Address Line 2:</b></span>";
echo "<span class='price'><input name='address2' type='text' id='address2' value='$_SESSION[address2]' size='24' />";
echo "</span>";
echo "<br><br>";
echo "<span><b>City/Town:</b></span>";
echo "<span class='price'><input name='city' type='text' id='city' value='$_SESSION[city]' size='24' />";
echo "</span>";
echo "<br><br>";
echo "<span><b>Postcode:</b></span>";
echo "<span class='price'><input name='postcode' type='text' id='postcode' value='$_SESSION[postcode]' size='24' />";
echo "</span>";
echo "<br><br>";
echo "<span><b>Country:</b></span>";
echo "<span class='price'><input name='country' type='text' id='country' value='$_SESSION[country]' size='24' />";
echo "</span>";
echo "<br><br>";
echo "<span><b>Email:</b></span>";
echo "<span class='price'><input name='email' type='text' id='email' value='$_SESSION[email]' size='24' />";
echo "</span>";
echo "</fieldset>";
echo "</form>";


}
}
?>



</body>
</html>
[ /code ]

Link to comment
https://forums.phpfreaks.com/topic/74448-sessions-and-update/#findComment-376140
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.