hi,
i found the below script in your forum and have trouble getting it to work. i keep getting the 'Error: the id is not an array!' message and also when i click on the 'Remove' link it will not work but if i put a tick in the remove box a click the delete button it works a treat but of course i still get the 'Error: the id is not an array!' message.
Also i have of course customised the script to fit my needs. Please help I very new to this. cheers
script:
<?php
include('db.php') ;
if (isset($_POST['remove']) && isset($_POST['id']) && is_array($_POST['id']))
{
foreach ($_POST['id'] as $id)
{
if (!mysql_query("DELETE FROM courses WHERE id = '$id'"))
{
echo error_message(sql_error());
}
}
}
else
{
echo "Error: the id is not an array!<br />\n";
}
$result = mysql_query("SELECT id, coursename FROM courses GROUP BY (id) ASC");
echo "<form action='{$_SERVER['PHP_SELF']}' method='POST'>\n".
" <table width='500' border='0' cellspacing='0' cellpadding='0'>\n".
" <tr valign='top'>\n".
" <td bgcolor=f1f1f1>Course ID</td>\n".
" <td bgcolor=f1f1f1>Course Name</td>\n".
" <td bgcolor=f1f1f1>Remove</td>\n".
" <td></td>\n".
" </tr>\n";
while ($row = mysql_fetch_array($result))
{
echo " <tr>\n".
" <td bgcolor=f1f1f1>".$row['id']. "</td>\n".
" <td bgcolor=f1f1f1>".$row['coursename']. "</td>\n".
" <td><input type='checkbox' name='id[]' value='{$row['id']}'>{$row['id']}</input></td>\n".
" <td><a href='{$_SERVER['PHP_SELF']}?action=delete_record&id={$row['id']}' onclick=\"return confirm('Are you sure you want to delete
record $id');\"> DELETE </a></td>\n".
" </tr>\n";
}
echo " <tr>\n".
" <td colspan='5' align='right'><input type='submit' name='remove' value='Delete' onclick=\"return confirm('Are you sure you want to delete
the selected records?');\" /></td>\n".
" </tr>\n".
" </table>\n".
"</form>";
?>
tom