I got a little help on this at PHPFreaks, though I still can't get it to take. The following code basically extracts data from a database, and prints it to a webform where the user can edit/update the records of their choosing.
Displaying the data in the form works fine, though updating does absolutely nothing.
Can anyone spot anything wrong with the code? The DB update code is towards the bottom.
Thanks in advance.
<?php
include '../../includes/db.php';
$query = "SELECT DISTINCT sym, id, e_date, e_price FROM symbols ORDER by sym";
$result = mysql_query($query);
$count = mysql_num_rows($result);
while($row = mysql_fetch_array($result)) {
?>
<tr>
<td><div align="center"><input name="checkbox[<?php echo $row['id'];?>]" id="checkbox[<?php echo $row['id'];?>]" type="checkbox" value="<? echo $row['id']; ?>"></div></td>
<td><input type="text" name="new_sym[<? echo $row['id'];?>]" id="new_sym" value="<? echo $row['sym']; ?>"></td>
<td><input type="text" name="new_e_date[<? echo $row['id'];?>]" id="new_e_date" value="<? echo $row['e_date']; ?>"></td>
<td><input type="text" name="new_e_price[<? echo $row['id'];?>]" id="new_e_price" value="<? echo $row['e_price']; ?>"></td>
<td>View/Edit Notes on this Record</td>
<td> </td>
</tr>
<?php
}
if($_POST['update'])
{
$new_sym=$_POST['new_sym'];
$new_e_date=$_POST['new_e_date'];
$new_e_price=$_POST['new_e_price'];
$checked = $_POST['checked'];
foreach($checked as $key => $value){
$id= $value;
$sql = "UPDATE symbols SET sym='$new_sym[$id]', e_date='$new_e_date[$id]', e_price='$new_e_price[$id]' WHERE id='$id'";
$result = mysql_query($sql) or die(mysql_error()."<br />SQL: $sql");
}
//if successful redirect to records.php
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=records.php\">";
}
}
mysql_close();
?>