I'm just learning PHP (extreme novice) and I'm struggling with deleting records using a checkbox included within each row.
I have a few idea but I'm not sure if my thoughts are correct. I think I need to turn it into a Form to be able to capture whats been checked but I would appreciate any guidance.
Most of the code I am using is from a solution a co-worker wrote for another solution and I learning by using it as a guide/example if some of it look advanced for an extreme novice.
Thanks in advance.
-------------------- Code showing to show the list ---------------------------
<?php
include_once('dAud_connect.php');
$dbh=mysql_connect($host,$user,$pass);
if (!$dbh)
{
echo "could not connect to database";
exit;
}
mysql_select_db($db);
{
$query = "select firstName, middleName, lastName, address1, address2, city, state, zip_code, country, phone, email, gender, citizenship, program, DATE_FORMAT(submitDate, '%m/%d/%Y') as submitDate, DATE_FORMAT(auditionDate, '%m/%d/%Y') as auditionDate from d_Aud";
}
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
if ($result)
{
echo "<table border=1>";
echo "<tr><th>firstName</th><th>middleName</th><th>lastName</th><th>Address1</th><th>Address2</th><th>city</th><th>state</th><th>zip</th><th>Country</th><th>phne</th><th>Email</th><th>Gender</th><th>Citizenship</th><th>Program</th><th>Audition Date</th><th>DateSubmitted</th><th>Delete</th></tr>";
while ($get_info = mysql_fetch_array($result))
{
echo "<tr>\n";
echo "\t<td>".stripslashes($get_info['firstName'])."</td>";
echo "\t<td>".stripslashes($get_info['middleName'])."</td>";
echo "\t<td>".stripslashes($get_info['lastName'])."</td>";
echo "\t<td>".stripslashes($get_info['address1'])."</td>";
echo "\t<td>".stripslashes($get_info['address2'])."</td>";
echo "\t<td>".stripslashes($get_info['city'])."</td>";
echo "\t<td>".stripslashes($get_info['state'])."</td>";
echo "\t<td>".stripslashes($get_info['zip_code'])."</td>";
echo "\t<td>".stripslashes($get_info['country'])."</td>";
echo "\t<td>".stripslashes($get_info['phone'])."</td>";
echo "\t<td>".stripslashes($get_info['email'])."</td>";
echo "\t<td>".stripslashes($get_info['gender'])."</td>";
echo "\t<td>".stripslashes($get_info['citizenship'])."</td>";
echo "\t<td>".stripslashes($get_info['program'])."</td>";
echo "\t<td>".stripslashes($get_info['auditionDate'])."</td>";
echo "\t<td>".stripslashes($get_info['submitDate'])."</td>";
echo "\t<td><input type='checkbox' name='del_me[]' value=\"$url\"></td>";
echo "</tr>\n";
}
echo "</table>";
}
echo mysql_error();
echo "<br />".$num_rows." records";
echo "<br /><a href='../php_inc/dAud_excel.php'>get as excel file</a>";
echo "<br /><a href='../php_inc/delete_entry.php'>delete check</a>";
?>
------------------ Code to Delete Rows ----------------------------
<?php
include_once('../php_inc/dAud_connect.php');
$dbh=mysql_connect($host,$user,$pass);
if (!$dbh)
{
echo "could not connect to database";
exit;
}
mysql_select_db($db);
$del_me = $HTTP_POST_VARS['del_me'];
$valid_user = $HTTP_SESSION_VARS['valid_user'];
if (count($del_me) >0)
{
foreach($del_me as $url)
{
if (delete_bm($valid_user, $url))
echo 'Deleted '.htmlspecialchars($url).'.<br />';
else
echo 'Could not delete '.htmlspecialchars($url).'.<br />';
}
}
?>