I've done some research into some other people's problems on here, but I can't quite see what's going wrong. I'm trying to update my form which already has the current user (who is logged in)'s data, but I want them to be able to update their profile.
This is what my code looks like:
<?php
// Retreive db data
$me = $_SESSION['username'];
require('db.php');
$data = "SELECT username, email FROM users WHERE username='$me'";
$query = mysql_query($data);
$data2 = mysql_fetch_array($query);
// Updating
$Username=$data2['username'] ;
$Email= $data2['email'] ;
if(isset($_POST['save']))
{
$username_save = mysql_real_scape_string($_POST['username']);
$email_save = mysql_real_scape_string($_POST['email']);
mysql_query("UPDATE users SET username ='$username_save', email ='$email_save' WHERE username = '$me'")
or die(mysql_error());
echo "Saved!";
}
?>
<form role="form">
<div class="form-group">
<label for="username">Username: </label>
<input type="text" class="form-control" name="username_save" value="<?php echo $data2['username']?>">
</div>
<div class="form-group">
<label for="pwd">Email Address: </label>
<input type="email" class="form-control" name="email_save" value="<?php echo $data2['email']?>">
</div>
<button input type="Submit" name="save" class="btn btn-info">Submit</button>
<button input type="Sumbit" name="delete" class="btn btn-danger">Delete</button>
</form>
When I submit my new values (the echo values works fine) and press submit (username=danielleeee [email protected]), my url looks like this:
pages/admin/edit.php?username_save=danielleeee&email_save=test%40danielle.com&save=
If anyone could shed some light on this for me that would be fantastic! Thank you.
mysql_functions, they have been deprecated for a long time now. Usemysqli_orPDOinstead. You are also vulnerable to SQL injection. Use prepared statements instead.