I want to have a profile page where I could view and edit information without using additional pages.
By default this information is printed:
<table border="0" style="width:35%">
<tr><td>E-mail:</td><td><?php echo $user['email']; ?></td></tr>
<tr><td>About me:</td><td><?php echo $user['about']; ?></td></tr>
</table>
<form action = "" method="post">
<input type = "submit" name="modify" value="Edit My Profile"/>
If POST['modify'] is selected do this:
<table border="0" style="width:25%">
<tr><td>E-mail:</td><td><input type="text" name="email" value="<?php echo $user['email']; ?>"/></td></tr>
<tr><td>About Me:</td></tr>
</table>
<textarea name="about" rows="4" cols="64"><?php echo $user['about']; ?></textarea>
<form action = "" method="post">
<input type = "submit" name="modify2" value="Edit My Profile"/>
<input type = "submit" name="cancel" value="Cancel"/>
</form>
If POST['modify2'] is selected do this:
$db = new mysqli('localhost', 'r00t', 'somepass', 'sometable');
$stmt = $db->prepare("UPDATE users SET email= ?, about= ? WHERE username = ?");
$stmt->bind_param('sss', $_POST['email'], $_POST['about'], $_SESSION['username']);
$stmt->execute();
$stmt->close();
redirect("profile.php");
It works as expected except when I try to edit my profile. I cannot overwrite email or About section. I think it has something to do with the MySQL query? I know I get my $_SESSION['username'] rigth. So can it be that $_POST['email'] or/and $_POST['about'] is not set?
I tried my query in PhpMyAdmin with the right arguments and it did work.
Or is it not possible to use double POST requests in single page?
Aucun commentaire:
Enregistrer un commentaire