Hello,
I am attempting to create a form which would allow update of fields in a database. Existing data stored in the database is used to populate the default values, and I want it so that they can change the fields and press a button to update the database. A differently named form appears on the page for each row in the database. The code uses a mixture of HTML and PHP.
However, when using the update button it does not update the database. Any help would be muchly appreciated
<?php $db = new mysqli ('*****','*****,'*****','*****');//connect to db
$results = $db->query("select * from images");
while ($row = $results->fetch_assoc()){?>
<form name="form[<?php echo $row['pkey']?>]" method="post" enctype="multipart/form-data" action="">
<h2><?php print $row['location']?></h2>
<table width="456">
<tr>
<td>Title: </td>
<td><input type="text" name="Title[<?php echo $row['pkey']?>]" value="<?php echo $row['title']?>" ></td>
</tr>
<tr>
<td>Type: </td>
<td><select name="type_sel[<?php echo $row['pkey']?>]">
<option><?php echo $row['type'];?></option>
<?php
$results2 = $db->query("select type from work_types");
while ($row2 = $results2->fetch_assoc()){?>
<option><?php echo $row2['type']?></option>
<?php }?>
</select></td>
</tr>
<tr>
<td>Collection: </td>
<td><select name="coll_sel[<?php echo $row['pkey']?>]">
<option><?php echo$row['type'];?></option>
<?php
$results3 = $db->query("select distinct coll_name from coll_name");
while ($row3 = $results3->fetch_assoc()){?>
<option><?php echo $row3['coll_name']?></option>
<?php }?>
</select></td>
</tr>
<tr>
<td>Date: </td>
<td><input type="text" name="date[<?php echo $row['pkey']?>]" /></td>
</tr>
<tr>
<td>Description: </td>
<td><textarea cols=80 rows=5 name="desc[<?php echo $row['pkey']?>]"></textarea></td>
</tr>
<tr>
<td><input name="Submit[<?php echo $row['pkey']?>]" type="submit" value="Upload image"></td>
</tr>
</table>
<?php
if(isset($_POST['Submit["'.$row['pkey'].'"]']))
{
$pkey = $row['pkey'];
print $pkey;
$title=$_POST['Title["'.$row['pkey'].'"]'];
$type_sel=$_POST['type_sel["'.$row['pkey'].'"]'];
$coll_sel=$_POST['coll_sel["'.$row['pkey'].'"]'];
$date=$_POST['date["'.$row['pkey'].'"]'];
$desc=$_POST['desc["'.$row['pkey'].'"]'];
$results4 = $db->query("UPDATE images SET title='$title' WHERE pkey='$pkey'");
}
?>
</form>
<?php
}
$db->close(); ?>
Thank you in advance for your help