Every time I click the button, the update does not work as expected. However, if I change the where id = 1 it works.
<?php
$x=$_GET['id'];
require 'db.php';
echo 'sqsas'.$x;
$stmt=$conn->prepare("select * from tbluser where id=:id");
$stmt->bindValue('id',$x);
$stmt->execute();
if(isset($_POST['btnEdit']))
{
$stmt=$conn->prepare('update tbluser set username = :un, password = :pw,email = :em where id=:id');
$stmt->bindValue(':id',$x);
$stmt->bindValue(':un',$_POST['txtUsername']);
$stmt->bindValue(':pw',$_POST['txtPassword']);
$stmt->bindValue(':em',$_POST['txtEmail']);
$stmt->execute();
//header("location:view.php");
}
?>
and here is the HTML form:
<?php while($row = $stmt->fetch(PDO::FETCH_OBJ)) {?>
<form method="post" action="edit.php">
<table>
<tr>
<td>id:</td>
<td><?php echo $row->id; ?></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="txtEmail" value="<?php echo $row->email; ?>" /></td>
</tr>
<tr>
<td>Username:</td>
<td><input type="text" name="txtUsername" value="<?php echo $row->username; ?>" /></td>
</tr>
<?php } ?>
<tr>
<td>Password:</td>
<td><input type="text" name="txtPassword" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="btnEdit" value="SAVE CHANGES" /></td>
</tr>
</table>
</form>
'update tbluser set username = :un, password = :pw,email = :em where id=:id'it is updating,... – BlondePainter Apr 17 '16 at 12:58