Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Björn Norén
Björn Norén
9,569 Points

Really need help: Edit username PHP

Hi! I have a School project and really need some help if that's possible, I'm getting somewhat desperate..

I need to figure out how how to edit/update a username once you have choosed one. The importance isn't that it is a name, the point is that it should work as a hotel when it's done and that you can change your name if you have typed it wrong for example. If you know a course that teaches you creating a hotel please let me know. Thanks Treehouse, you are awesome

This is how far I have gone so far:

http://studenter.miun.se/~bjno1501/dt057g/php/moment2/practise/sessions.php

Here's the code:

--- sessions.php ---

<head> <meta charset="utf-8"> </head> <body> Sessions

<?php session_start();

if(isset($_POST['user'])) { 
    $user = $_POST['user'];             
    $_SESSION['username'] = $user; 
} 

if(isset($_SESSION['username'])) { 

    echo "<p class='message box'>Sessions-username: " . $_SESSION['username'] . " " . 
    "<a href='logout.php' class='rightbutton'><button class='btn btn-danger'>Log out</button></a>" . 
    "</p>\n"; 
} 

?>

<form method="post" class="form-inline">

Name: <input type="text" name="user" class="form-control"> 
<input type="submit" value="Save user" class="btn btn-info"> 

</form> </body> --- logout.php ---

session_start(); session_destroy();

header("Location: sessions.php");

1 Answer

If the user puts in the wrong user name, they could just type the correct one in and click "Save User" again. The new value will overwrite the old one and you're good to go, or at least that seems to be how the script works. Or maybe i'm misunderstanding the question. If so, please elaborate. Good luck!