Page 1 of 1

Deletion question

Posted: Tue Feb 02, 2010 1:39 pm
by jefffan24
I have a script running to make a deletion link and it works but when you click it, it deletes the record but it also keeps the link until you refresh the page.

So like lets say it was like

Bob | *link*Delete?*link*

You click the delete link, the record is no longer in the database but the line above still shows until you refresh the page. Is there anyway to stop this from happening? Also here is my code if it helps ignore all the if statements I know switch/case would have been better I'm just too lazy to go change them right now.

Code: Select all

 
$sql = "SELECT * FROM drivers ORDER BY Name";
    $result = mysql_query($sql);
    
    $id = $_GET[ID];
    $delete = mysql_query("DELETE FROM drivers WHERE ID = $id");
        
    while($list = mysql_fetch_assoc($result)){
        
        echo $list['Name'];
        if($list['Link'] != null){
        echo ' | <a href="http://trukz.com/driver_display.asp?ID=' . $list['Link'] . '" target="_blank">Link to Driver Page</a> | ';
        }
        else if($list['Link'] == null){
            echo ' | No Link | ';
        }
        if(!$_COOKIE['InfoSec'] == 1){
            if($list['Company'] == "NA"){
                echo 'Haulin Glass Expediting<br /><br />';
            }
            if($list['Company'] == "EU"){
                echo 'Haulin Glass Europe<br /><br />';
            }
            if($list['Company'] == "AU"){
                echo 'Haulin Glass Australia<br /><br />';
            }
        }
        if($_COOKIE['InfoSec'] == 1){
            if($list['Company'] == "NA"){
                echo 'Haulin Glass Expediting | <a href="drivers.php?ID=' . $list['ID'] . '">Delete?</a><br /><br />';
            }
            if($list['Company'] == "EU"){
                echo 'Haulin Glass Europe | <a href="drivers.php?ID=' . $list['ID'] . '">Delete?</a><br /><br />';
            }
            if($list['Company'] == "AU"){
                echo 'Haulin Glass Australia | <a href="drivers.php?ID=' . $list['ID'] . '">Delete?</a><br /><br />';
            }
        }
    }
 
 

Re: Deletion question

Posted: Tue Feb 02, 2010 5:27 pm
by JakeJ
Put inside a frame and just refresh the frame or use ajax.

Re: Deletion question

Posted: Tue Feb 02, 2010 5:31 pm
by social_experiment
This code does something similar to what you want but it's one page being used over and over. You have a page that displays all the records with a delete link next to them, as per your example. In the code i created i used that same page to also delete the record. When you access the page, there is no query string set. Once you click on the delete link the page is opened (same page) this time with a querystring that carries the name 'ID' and value of the record id out of the database. The script checks whether or not the querystring has been set, if not the page displays all records. If the value is set, the script deletes that selected record, then again displays all records from the database.

Code: Select all

<?php
    if (!isset($_GET['ID']) || $_GET['ID'] == '') {
        mysql_connect('???', '???', '???');
        mysql_select_db('???');
        
        $query = mysql_query("SELECT * FROM table");
        
        while ($pointer = mysql_fetch_assoc($query)) {
            echo $pointer['username']." <a href=\"Untitled-2.php?ID=".$pointer['id']."\">Delete ".$pointer['id']."</a>";
            echo '<br />';
        }
    }
    else {
        mysql_connect('???', '???', '???');
        mysql_select_db('???');
        
        $deleteQuery = mysql_query("DELETE FROM table WHERE id = '".mysql_real_escape_string($_GET['ID'])."' ");        
        
        $query = mysql_query("SELECT * FROM table");
        
        while ($pointer = mysql_fetch_assoc($query)) {
            echo $pointer['username']." <a href=\"Untitled-2.php?ID=".$pointer['id']."\">Delete ".$pointer['id']."</a>";
            echo '<br />';
        }
    }
?>

Re: Deletion question

Posted: Thu Feb 04, 2010 4:36 pm
by jefffan24
Thank you so much social experiemnt that works perfectly :D