Php edit user form

I created a user form and sessions has started i have confirmed because it displays user info on there profile page when they login… my issue is if i click settings it will go to a settings.php and display a form with there info and they can update it if needed… however i cannot get the data to display in the form… the only way i have been able to is if i add ?edit=uid to the end of the url then it shows up. this is the code in my edit form php my includes are header and footer and db connection… I have been every where no help.

<?php $email = ""; $username = ""; $birthdate = ""; if(isset($_GET['edit'])){ $uid = escape($_GET['edit']); $sql = "SELECT * FROM users WHERE uid = '".$_SESSION['uid']."'"; $result = query($sql); while (($row = mysqli_fetch_assoc($result)) !=false) { $uid = $row['uid']; $email = $row['email']; $username = $row['username']; $birthdate = $row['birthdate']; } } ?>

You fail to use the session in settings.php page. So, you have to pass the variable another way. If you want to continue with the session way, which I would recommend, you need to add session_start to the top of any page where you want access to the session variables.

If you do go that route, you can drop the $_GET part of the version.

session is already started in my int include file in the header.

Did you write your own database wrapper?

What does query() return?

I would go with this version of the while:

[php]while ($row = mysqli_fetch_assoc($result)) {

$uid = $row['uid'];
$email = $row['email'];
$username = $row['username'];
$birthdate = $row['birthdate'];

}[/php]

BUT, should you be doing this in a loop? Wouldn’t they only be updating their information, not a list of people associated with them?

I wrote helper functions so all i am doing is looping myself in a corner… all i want to do is let a user update there 4 little fields and its proving to be dificult

$connection = mysqli_connect(‘localhost’, ‘root’, ‘’, ‘db’);

if($connection) {
echo “We are connected”;
} else {
die(“Database connection failed”);
}

function row_count($result)
{
return mysqli_num_rows($result);
}

function escape($string)
{
global $connection;
return mysqli_real_escape_string($connection, $string);
}

function query($query)
{
global $connection;
return mysqli_query($connection, $query);
}

function confim($result)
{
global $connection;
if (! $result) {
die(“QUERY FAILED” . mysqli_error($connection));
}
}

function fetch_array($result)
{
global $connection;
return mysqli_fetch_array($result);
}
?>

i dont know what i should be doing im trying to figure it out

Forget all those ridiculous functions. They are far from helpers.

Start with this Psuedo code and make it real.

if server request = post{
update table set col1=?,col2=?, col3=?,col4=? where user_id = ?
}

Check out this excellent PDO tutorial. Once you go PDO you will never go back.
https://phpdelusions.net/pdo

this is what frustrates me about learning php i take a course one way try to get help understanding that way and i never really get a answer just told to do it another way. thanks for the help appreciate it ill figure it out.

Try downloading the PDO bumpstart database in my signature. You will be up and running in minutes. Study the code to see how things work. It will be well worth your time in the long run.

Sponsor our Newsletter | Privacy Policy | Terms of Service