I'm making a page where it shows the "unprocessed" transactions. Each record will have a link where the user will click on it once it's "processed". On the top of the page there is also a link to "processed" transactions. The link directs to the same page by using PHP_SELF.
My question is this: How would I update the status from 0 to 1 when the user clicks on "this record has been processed" link and use the same page using $SEVER[PHP_SELF]
Here's my code so far. Thanks:
<?php
include("_adminCommon.php");
require_once "../_creditCardFunctions.php";
echo("<h1>Credit Card Transactions</h1>\n");
$type = $_GET[type];
if (!$type) {
$type = unprocessed;
$status = 0;
} elseif ($type == processed) {
$status = 1;
} else {
$status = 0;
}
if ($type ==unprocessed ) {
$link = $_SERVER['PHP_SELF']."?type=processed";
$processed_query = "UPDATE payments set status = '$status' where payment_id = '$id'";
$myQuery = new Query($processed_query);
$display=processed;
} else {
$link = $_SERVER['PHP_SELF']."?type=unprocessed";
$display=unprocessed;
}
echo "<p>Link to :<a href=$link>$display</a>";
echo "<p> Type: $type";
echo "<p> Status: $status";
$query = "SELECT * FROM payments where status=$status ORDER BY date DESC";
$myQuery = new Query($query);
//Get record using class
for ($i=0; $i < $myQuery->num_rows; $i++) {
$data = $myQuery->row_array();
$paymentId = $data[paymentId];
$cc_first = $data[cc_first];
$cc_last = $data[cc_last];
$cc_address = $data[cc_address];
$cc_city = $data[cc_city];
$cc_state = $data[cc_state];
$cc_zip = $data[cc_zip];
$cc_phone = $data[cc_phone];
$cc_email = $data[cc_email];
$totalAmount = $data[totalAmount];
$cc_number = $data[cc_number];
$cc_expMonth = $data[cc_expMonth];
$cc_expYear = $data[cc_expYear];
$cc_type = $data[cc_type];
$date = $data[date];
$companyName = $data[companyName];
$eventId = $data[eventId];
$cc_number = stripslashes($cc_number);
$cc_number = DecryptCard(trim($cc_number));
if ($cc_type == "v") {
$cc_type = "Visa";
} elseif ($cc_type == "m") {
$cc_type = "MasterCard";
} elseif ($cc_type == "a") {
$cc_type = "American Express";
}
$date = date("n/j/Y", $date);
if ($eventId == 0) {
$reason = "Membership Applicatoin";
} else {
$query = "SELECT title, datetime FROM calendar WHERE eventId = $eventId";
$eventQuery = new Query($query);
$eventData = $eventQuery->row_array();
$event = $eventData[title];
$eventDate = $eventData[datetime];
$eventDate = date("n/j/Y", $eventDate);
$reason = "RSVP: $event on $eventDate";
}
//Output transactions
echo("<table><tr><td><p>$date charge for \$$totalAmount<br>
$cc_first $cc_last / $companyName<br>
$cc_address; $cc_city, $cc_state $cc_zip<br>
$cc_phone - <a href=mailto:$cc_email>$cc_email</a><br>
$cc_type - $cc_number - Exp($cc_expMonth/$cc_expYear)<br>
$reason<br></td>");
if ($type ==unprocessed){
echo ("<td valign=top> <a href=\"$link".$data["payment_id"]."\">Unprocessed</a><td></tr>
<hr width=100 align=center></p>
</table>\n");
} elseif ($type==processed){
echo ("<td valign=top> <a href=\"$link".$data["payment_id"]."\">Processed</a><td></tr>
<hr width=100 align=center></p>
</table>\n");
}
$id= $data["payment_id"];
}
EndAdminPage();
?>