I have looked all over the WWW and the forum, but could not find an answer to work. I want to update my post on .........../post.php?id=19
this is my function:
function update_user($conn) {
if(isset($_GET['id'])) {
$id = $_GET['id'];
$name = $_POST['name'];
$age = $_POST['age'];
$sql = "UPDATE users SET name =':name', age = ':age' WHERE id=':id'";
$query = $conn->prepare($sql);
$query->execute( array( ':name'=>$name, ':age'=>$age, ':id' => $id ));
}
}
And this is my form:
<h3>Update a user</h3>
<?php update_user($conn) ?>
<form name="myForm2" method="POST" action= "">
<label>Name:</label><input type="text" id="name" name="name">
<label>Age:</label><input type="text" id= "age" name="age">
<input type="submit" value="add" name="update">
I have no errors but the POST just returns the old record without the update I filled in the form.
Hope someone can assist me, thanks a million. Bas
PS. the $conn is correct and works when insering or printing posts.