Hi all,
here's a summary of what I intend to do: I have a form, which shows new accounts which need to be checked by an administrator to either approve or delete them from the database. I intend to use checkboxes so that the administrator can delete/approve as many as they wish. I have two submit buttons, each for approve and delete, and the idea is that when a button is submitted, it will either delete or approve the accounts and then load the remaining accounts again. I would like the page to be self-loading but I am having some trouble when accepting the post values when clicking on either button.
Here are the 2 error messages:
Notice: Undefined index: Delete in /var/www/html/phpTrafficA-2.0.1/Php/Functions/audit.php on line 7
Notice: Undefined index: Add in /var/www/html/phpTrafficA-2.0.1/Php/Functions/audit.php on line 12
NB: $c contains the database connection information. The page is loaded from index.php and the show_users function is called. This bit is not a problem, but it is the 2 POST problems I have.
And the corresponding code:
<?php
function show_users($c)
{
global $count;
global $lang;
if ($_POST['Delete'])
{
delete_users($c,$_POST['checkbox'],$_POST['count']);
}
else if ($_POST['Add'])
{
approve_users($c,$_POST['checkbox'],$_POST['count']);
}
?>
<?php
$tbl_name="tblcandidate";
$sql="SELECT * FROM $tbl_name where checked=false";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<table width="700" border="0">
<form action="./index.php" method="post">
<tr>
<td align="center" bgcolor="#FFFFFF"></td>
<td align="center" width="250"><font-size=3px>Name</font></td>
<td align="center" bgcolor="#FFFFFF"><font-size=3px>Gender</font></td>
<td align="center" bgcolor="#FFFFFF"><font-size="3px">Email</font></td>
<td align="center" bgcolor="#FFFFFF"><font-size=3px>Home Tel</font></td>
<td align="center" bgcolor="#FFFFFF"><font-size="3px">Mobile Tel</font></td>
<td align="center" bgcolor="#FFFFFF"><font-size="3px">Work Tel</font></td>
<td align="center" bgcolor="#FFFFFF"><font-size="3px">Qualification</font></td>
<td align="center" bgcolor="#FFFFFF"><font-size="3px">Course Name</font></td>
<td align="center" bgcolor="#FFFFFF"><font-size="3px">Highest Position</font></td>
<td align="center" bgcolor="#FFFFFF"><font-size="3px">Sector</font></td>
<td align="center" bgcolor="#FFFFFF"><font-size="3px">Years Worked</font></td>
</tr>
<?php
$count=0;
while($rows=mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "<tr>";
echo "<td align=\"center\" bgcolor=\"#FFFFFF\"><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"".$rows['id']."\"></td>"; ?>
<td width="250"><?php echo $rows['name']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['gender']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['email']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['home']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['mobile']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['work']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['edtype']; ?></td>"
<td bgcolor="#FFFFFF"><?php echo $rows['coursename']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['hipostitle']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['ExSector']; ?></td>"
<td bgcolor="#FFFFFF"><?php echo $rows['yearsworked']; ?></td>
</tr>
<?php
$count++;
}
?>
</table>
<table width="700" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#FFFFFF"><input name="Delete" type="Submit" value="Delete"></td>
<td bgcolor="#FFFFFF"><input name="Add" type="Submit" value="Approve">
</td>
</tr>
</table></form>
</table>
<?php
}
?>
<?php
function delete_users($c,$id,$count)
{
$tbl_name="tblcandidate";
for($i=0;$i<$count;$i++)
{
$sql = "DELETE FROM $tbl_name WHERE id='$id'";
}
}
function approve_users($c,$id,$count)
{
$tbl_name="tblcandidate";
for($i=0;$i<$count;$i++)
{
$sql = "UPDATE $tbl_name SET checked=true WHERE id='$id'";
}
}
?>
Can anyone help solve this problem for me?
Cheers,
Ben