Hi,
Basically, I'm trying to write a script that will list the contents of a mySQL table and print a listbox next to every entry with "yes" or "no". When the user submits the form, I want to be able to delete all the "no" entries from the table.
The problem lies in the form processing code but I can't find it!!
if ($Process == "Process") {
$i = 0;
while ($i < mysql_num_rows ($result)) {
$checkval = "$" . "action" . $i;
if ( $checkval == "no" ) {
echo( $checkval );
$delrec = @("DELETE FROM Patrons_Pending WHERE ID=" . $i . ";");
if (!$delrec) {
echo( $text1 . "Error performing delete:" . mysql_error() . $text2 );
exit();
}
}
$i++;
}
}
(each listbox is known as "action1"..."action99" etc..)
Full code is below, PLEASE HELP! Thanks 🙂
<?php
//========================================================================
// Connect to the database server
//========================================================================
include ("/home/sites/www.minus18.org/mysql_auth.inc");
$dbcnx = @mysql_connect("$conf1", "$conf2", "$conf3");
if (!$dbcnx) {
echo( $text1 . "FATAL ERROR - Unable to connect to database." . $text2 );
exit();
}
//========================================================================
// Select database
//========================================================================
if (! @mysql_select_db("$conf4") ) {
echo( $text1 . "FATAL ERROR - Unable to access database." . $text2 );
exit();
}
//========================================================================
// Get Data
//========================================================================
$result = @("SELECT FROM Patrons_Pending ORDER BY ID;");
if (!$result) {
echo( $text1 . "Error performing query:" . mysql_error() . $text2 );
exit();
}
//========================================================================
// Display Data
//========================================================================
$result = @("SELECT FROM Patrons_Pending ORDER BY ID;");
if (!$result) {
echo( $text1 . "Error performing query:" . mysql_error() . $text2 );
exit();
}
echo( "<table border=\"0\" cellspacing=\"2\" cellpadding=\"0\">
<form name=\"approve\" method=\"post\" action=\"$PHP_SELF\">
<tr>
<td>OK</td>
<td>ID</td>
<td>Firstname</td>
<td>Lastname</td>
<td>Postcode</td>
<td>State</td>
<td>DOB</td>
<td>Identity</td>
<td>Email</td>
<td>Mailinglist</td>
<td>Emailbouncing</td>
<td>Created</td>
</tr>" );
while ( $row = mysql_fetch_array($result) ) {
echo( "<tr><td><select name=\"action" . $row["ID"] . "\">
<option value=\"approve\">yes</option>
<option value=\"no\">no</option>
</select><td>" . $row["ID"] . "</td><td>" . $row["Firstname"] . "</td><td>" . $row["Lastname"] . "</td><td>" . $row["Postcode"] . "</td><td>" . $row["State"] . "</td><td>" . $row["DOB"] . "</td><td>" . $row["Identity"] . "</td><td>" . $row["Email"] . "</td><td>" . $row["Mailinglist"] . "</td><td>" . $row["Emailbouncing"] . "</td><td>" . $row["Created"] . "</td></tr>" );
}
echo( "</table> <input type=\"submit\" name=\"Process\" value=\"Process\">" );
//========================================================================
// Process Remove Form
//========================================================================
if ($Process == "Process") {
$i = 0;
while ($i < mysql_num_rows ($result)) {
$checkval = "$" . "action" . $i;
if ( $checkval == "no" ) {
echo( $checkval );
$delrec = @("DELETE FROM Patrons_Pending WHERE ID=" . $i . ";");
if (!$delrec) {
echo( $text1 . "Error performing delete:" . mysql_error() . $text2 );
exit();
}
}
$i++;
}
}
?>