Ovidiu G Ovidiu G - 6 months ago 11
SQL Question

Can't update fields from db

I'm trying to update some fileds in the database using a form and for some reason it just refreshes the page without doing anything. Here's the code I used:

<?php

$id = $_GET["id"];
$select = "SELECT * FROM blog_members WHERE memberID = '$id'";
$result = mysqli_query($link, $select);
$row=mysqli_fetch_assoc($result);
$id2=$row['memberID'];
$username=$row['username'];
$password = $row['password'];
$email = $row['email'];
?>

<form id="form" action="#" method="post">
<br><table cellspacing='0' cellpadding='0'>
<tr><td>Username:</td>
<td><input name="username" type="text" id="username" placeholder="<?php echo $username; ?>" size="25" /></td></tr>
<tr><td>Password:</td>
<td><input name="password" type="text" id="password" placeholder="<?php echo $password; ?>" size="25" /></td></tr>
<tr><td>Email:</td>
<td><input name="email" type="text" id="email" placeholder="<?php echo $email; ?>" size="25" /></td></tr>
</table>
<br>
<input type="submit" name="Edit" value="Save" />
</center></form>

<?php

if(isset($POST['Edit'])){
$username2 = $_POST['username'];
$password2 = $_POST['password'];
$email2 = $_POST['email'];

$edit = mysqli_query($link, "UPDATE blog_members SET username='$username2',password='$password2',email='$email2' WHERE memberID='$id2'");
$result1 = mysqli_query($link,$edit);

if(!$result){
echo mysqli_error($link);
}else{
echo "Changes have been saved successfully!";
echo "<meta http-equiv=\"refresh\" content=\"2;URL=view-users.php\">";
}

}
?>


I think the query $edit it's not working properly since the page just gets refreshed and the fields from the databse are not updated. I feel like I'm missing something. Any suggestions?

Answer

Also change below code

if(isset($POST['Edit'])){

with this, $_POST is right syntax not $POST

if(isset($_POST['Edit'])){
Comments