Hello.
I am trying to create an update form that will update values in a MySQL database.
The forms are generated for each different row in the database through a while loop (ie whilst there is another row, make a new form on the page).
However, I cannot get it to update to the databse correctly, having tried numerous different configurations.
I did try making it so that each aspect of the form had a name such as Title[$counter], but this did not work at all. I was told setting id tags on the inputs might help, but I'm not sure how that would work
The code below updates every field in the database, probably as each form on the page has the same name and contents
<?php $db = new mysqli ('localhost','***','***','***');//connect to db
$results = $db->query("select * from images");
while ($row = $results->fetch_assoc()){
$counter=$row['pkey'];?>
<form name="newad" method="post" enctype="multipart/form-data" action="">
<table width="456">
<tr>
<td>Title: </td>
<td><input type="text" name="Title" value="<?php echo $row['title']?>" ></td>
<td><input type="submit" name="Submit" /></td></tr>
</table>
</form>
<?php
if(isset($_POST['Submit']))
{$title=$_POST['Title'];
$results4 = $db->query("UPDATE images SET title='$title' WHERE pkey='$counter'");
}}
$db->close(); ?>
Closing the while loop before the if state ment causes the database to update only the last row. There are other fields to update in the databse, but I'd like to get one working first.
Any help would be appreciated.
Thanks