SlanginBeef.com – del_pre_trans_item.php


<?php # del_pre_trans_item.php
// This script will be the base page to set up the user's profile
require ('includes/config.inc.php'); 
$page_title = 'Delete Pre Transaction Item';
include ('includes/header.html');
require (MYSQL);    // Need the database connection:


// If no first_name session variable exists, redirect the user:
if (!isset($_SESSION['person_id'])) {
    $url = BASE_URL . 'index.php'; // Define the URL.
    ob_end_clean(); // Delete the buffer.
    header("Location: $url");
    exit(); // Quit the script.
}


// header
echo "<h1>$page_title</h1><br />";

refresh_session(0); // Refresh session settinings incase of previous changes


// Check for a valid worker ID and product ID, through GET or POST:
if ( (isset($_GET['toi_id'])) && (is_numeric($_GET['toi_id'])) && 
        (isset($_GET['wid'])) && (is_numeric($_GET['wid'])) && 
        (isset($_SESSION['worker_id'])) && ($_SESSION['worker_id'] ==  $_GET['wid']) ) { // From add_deal.php
    $toi_id = $_GET['toi_id'];

} else { // No valid ID, kill the script.
    echo '<p class="error">This page has been accessed in error.</p>';
    include ('includes/footer.html'); 
    exit();
}





//Delete the item from the database:
try {
    $dbc->autocommit(FALSE); // i.e., start transaction
    
    $q = "DELETE FROM temp_order_item WHERE item_number=$toi_id LIMIT 1";        
    $r = @mysqli_query ($dbc, $q);
    if (mysqli_affected_rows($dbc) != 1) { // If it ran OK.
        throw new Exception($dbc->error);
        trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
    }
    
    // our SQL queries have been successful. commit them
    // and go back to non-transaction mode.
    $dbc->commit();
    $dbc->autocommit(TRUE); // i.e., end transaction
    $passed = TRUE;
}
catch ( Exception $email ) {
    $dbc->rollback(); 
    $dbc->autocommit(TRUE); // i.e., end transaction   
    $passed = FALSE;
}
    
    
if ($passed) { // If it ran OK.
    // Finish the page:
    echo '<h3>The item has been deleted.</h3>';
    // forward to edit_inventory_info.php in 2 seconds
    $url = BASE_URL . 'add_deal.php';
    header('Refresh: ;url=' . $url . ''); 
    include ('includes/footer.html'); // Include the HTML footer.
    exit(); // Stop the page.
    
} else { // If the query did not run OK.
    echo '<p class="error">The changes did not take place due to a system error.<br>
        The user has NOT been deleted.<br>
        We apologize for any inconvenience.</p>';
    // forward to profile.php in 2 seconds
    $url = BASE_URL . 'add_deal.php';
    header('Refresh: 5;url=' . $url . ''); 
    include ('includes/footer.html'); // Include the HTML footer.
    exit(); // Stop the page.
}







include ('includes/footer.html');

?>