Jump to content

How to get the cancel button to work ?


Davie33

Recommended Posts

Hi can anyone tell me plz how i can get my cancel button to work plz.

The problem i am having is that after i hit the delete checked button i get a var response is u can see in javascript that gives u two buttons to pick from.

1 ok //thats to delete all checked// and the 2nd button is cancel but when i hit cancel it still deletes all checked.

These two buttons show after u click on delete checked.

 

This is the javascript for it.

elseif(isset($_POST['deletechecked'])) {
    $count = count($_POST['checkbox']);
    ?>
    <script type = "text/javascript">
        var response = confirm("Are you sure you want to delete <?php echo $count;?> game(s)?");
        if (!response) {
            window.location.href = '<?php echo $siteurl;?>admin/index.php?act=managegames&remove=notta';
            
        }
    </script>

 

this is the checkbox delete code

 

<?php
    foreach ($_POST['checkbox'] as $box) {
        $query = yasDB_select("SELECT id, file, thumbnail FROM games WHERE id = '$box'",false);
        if($query->num_rows == 0) {
            echo 'You cannot delete a game that does not exist!<br />';
            echo '<a href="index.php?act=managegames">Click here to go back</a>';
        } else {
            if ($_GET['remove'] != 'notta') {
                $row = $query->fetch_array(MYSQLI_ASSOC);
                @unlink('../' . $row['file']);
                @unlink('../' . $row['thumbnail']);
                $query->close();            
                yasDB_delete("delete from games where id = '$box'",false);
                ?>
                <meta http-equiv="refresh" content="0;URL=<?php echo $siteurl;?>admin/index.php?act=managegames" />
                <?php
            }
        }

Link to comment
Share on other sites

Hi this is most of the code thats got the check delete.

 

<div id="nav_header"><font size="+1" color=red><i>Manage Games</i></font></div><br/>
<div id="tablecontent">
<?php
if(!empty($_GET['edit'])) {
    $query = yasDB_select("SELECT * FROM games WHERE id = '{$_GET['edit']}'",false);
    if($query->num_rows == 0) {
        echo 'You cannot edit a file that doesnt exist.';
        $query->close();
        
    } else {
        $row = $query->fetch_array(MYSQLI_ASSOC);
        $query->close();
        $catName = array();
        $catId = array();
        $i = 0;
        $query = yasDB_select("SELECT id, name FROM categories",false);
        while($names = $query->fetch_array(MYSQLI_BOTH)) {
            $catName[$i] = $names['name'];
            $catId[$i] = $names['id'];
            $i++;
        }
        $query->close();
        ?>
        <center><form name="edit" method="post" action="index.php?act=managegames">
        Title:<br/>
        <input type="text" name="title" value="<?php echo $row['title'];?>"  /><br/>
        Game Height:<br/>
        <input type="text" name="gameheight" value="<?php echo $row['height'];?>" /><br/>
        Game Width:<br/>
        <input type="text" name="gamewidth" value="<?php echo $row['width'];?>" /><br/>
        Description:<br/>
        <textarea name="description" /><?php echo $row['description'];?></textarea><br/>
        Instructions:<br/>
        <textarea name="instructions" /><?php echo $row['instructions'];?></textarea><br/>
        Keywords:<br/>
        <textarea name="keywords" /><?php echo $row['keywords'];?></textarea><br/>
        Category:<br/>
        <select name="category">
        <option value="<?php echo $row['category'];?>"><?php echo $catName[$row['category']-1];?></option>
        <?php
        $len = count($catName);
        for($i=0;$i<$len;$i++) {
        ?><option value="<?php echo $catId[$i];?>"><?php echo $catName[$i];?></option>
        <?php } ?></select><br/>
        Thumbnail:<br/>
        <input type="text" name="thumbnail" value="<?php echo $row['thumbnail'];?>"  /><br /><br/>
        File:<br/>
        <select name="type">
        <option value="<?php echo $row['type'];?>"><?php echo $row['type'];?></option>
        <option value="SWF">swf</option>
        <option value="DCR">dcr</option>
        <option value="FLV">flv</option>
        <option value="WMV">wmv</option>
        <option value="AVI">avi</option>
        <option value="MPG">mpg</option>
        <option value="MOV">mov</option>
        <option value="IMAGE">image</option>
        <option value="YOUTUBE">youtube</option>
        </select><br/>
        <input type="text" name="file" value="<?php echo $row['file'];?>"/><br/>
        </select><br/>
        <input type="hidden" name="id" value="<?php echo $row['id'];?>"/>
        <input type="hidden" name="m" value="<?php echo $_GET['m'];?>"/>
        <input type="submit" name="edit" value="Edit!"/> 
        <input type="reset" name="reset" value="Reset"/>
        </form></center>
    <?php            
    }
    
} elseif(isset($_POST['edit'])) {
    if(empty($_POST['title']) || empty($_POST['thumbnail'])) {
        echo 'One or more fields was left empty.<br />';
        echo '<a href="index.php?act=managegames&edit=' . $_POST['id'] . '">Click here to go back</a>';
    } else {
        yasDB_update("UPDATE games SET title = '{$_POST['title']}', description = '{$_POST['description']}', instructions = '{$_POST['instructions']}',keywords = '{$_POST['keywords']}', category = '{$_POST['category']}', height = '{$_POST['gameheight']}', width = '{$_POST['gamewidth']}', type = '{$_POST['type']}', thumbnail = '{$_POST['thumbnail']}', file = '{$_POST['file']}' where id = '{$_POST['id']}'",false);
        echo '<p align="center">File Successfully edited!<br />';
        if (!empty($_POST['m'])) {
            echo '<a href="index.php?act=managegames">Click here to proceed</a></p>';
        } else {
            echo '<a href="index.php?act=brokenfiles">Click here to proceed</a></p>';
        }
    }
} elseif(!empty($_GET['delete'])) {
    $query = yasDB_select("SELECT id, file, thumbnail FROM games WHERE id = '{$_GET['delete']}'",false);
    if($query->num_rows == 0) {
        echo 'You cannot delete a game that does not exist!<br />';
        echo '<a href="index.php?act=managegames">Click here to go back</a>';
    } else {
        $row = $query->fetch_array(MYSQLI_ASSOC);
        @unlink('../' . $row['file']);
        @unlink('../' . $row['thumbnail']);
        $query->close();
        yasDB_delete("delete from games where id = '{$_GET['delete']}'",false);
        echo '<p style="text-align:center;">Game successfully deleted.<br />';
        echo '<a href="index.php?act=managegames">Click here to proceed</a></p>';
    }
} elseif(isset($_POST['deletechecked'])) {
    $count = count($_POST['checkbox']);
    ?>
    <script type = "text/javascript">
        var response = confirm("Are you sure you want to delete <?php echo $count;?> game(s)?");
        if (!response) {
            window.location.href = '<?php echo $siteurl;?>admin/index.php?act=managegames&remove=notta';
            
        }
    </script>
    <?php
    foreach ($_POST['checkbox'] as $box) {
        $query = yasDB_select("SELECT id, file, thumbnail FROM games WHERE id = '$box'",false);
        if($query->num_rows == 0) {
            echo 'You cannot delete a game that does not exist!<br />';
            echo '<a href="index.php?act=managegames">Click here to go back</a>';
        } else {
            if ($_GET['remove'] != 'notta') {
                $row = $query->fetch_array(MYSQLI_ASSOC);
                @unlink('../' . $row['file']);
                @unlink('../' . $row['thumbnail']);
                $query->close();            
                yasDB_delete("delete from games where id = '$box'",false);
                ?>
                <meta http-equiv="refresh" content="0;URL=<?php echo $siteurl;?>admin/index.php?act=managegames" />
                <?php
            }
        }
    }
} else {
    if (isset($_GET['page'])) {
       $pageno = $_GET['page'];
    } else {
       $pageno = 1;
    } 
    $result = yasDB_select("SELECT count(id) FROM games");
    $query_data = $result->fetch_array(MYSQLI_NUM);;
    $numrows = $query_data[0];
    $result->close();
    
    $rows_per_page = 20;
    $lastpage = ceil($numrows/$rows_per_page);
    $pageno = (int)$pageno;
    if ($lastpage < 1) {
        $lastpage = 1;
    }
    if ($pageno < 1) {
       $pageno = 1;
    } elseif ($pageno > $lastpage) {
       $pageno = $lastpage;
    } 
    $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
    echo '<table width="885">
    <tr>
    <td><font color=red><i>ID</i></font></td>
    <td></td>
    <td><font color=red><i>Title</i></font></td>
    <td><font color=red><i>Description</i></font></td>
    <td><font color=red><i>Category</i></font></td>
    <td></td>
    <td></td>
    </tr>';
    $query_cats = yasDB_select("SELECT name FROM categories");    
    $cats = array();
    $i = 0;
    while ($catRow = $query_cats->fetch_array(MYSQLI_ASSOC)) {;
        $cats[$i] = $catRow['name'];
        $i++;
    }
    $query_cats->close();
    $query = yasDB_select("SELECT * FROM games ORDER BY `id` DESC $limit");
    if($query->num_rows==0) {
    } else { 
        ?><form name="deleteform" method="post" action=""><?php
        while($row = $query->fetch_array(MYSQLI_ASSOC)) {
            echo '<tr>
                <td>' . $row['id'] . '</td>
                <td><img src="' . $siteurl . $row['thumbnail'] . '" style="width: 60px; height: 50px;" /></td>
                <td>' . $row['title'] . '</td>
                <td>' . $row['description'] . '</td>
                <td>' . $cats[$row['category']-1] . '</td>
                <td><font color=red><i><a href="index.php?act=managegames&edit=' . $row['id'] . '&m=1">Edit</a></i></font></td>
                <td><br/><font color=red><i><a href="index.php?act=managegames&delete=' . $row['id'] . '" onclick="return confirm(\'Are you sure you want to delete this game?\')">Delete</a></i></font>
                <br/>
                   <input name="checkbox[]" type="checkbox" id="checkbox[]" value="'. $row['id']. '">
                </td>
                </tr>';
        }
    }
    unset ($cats);
    $query->close();
    ?>
    </table>
    <div style="text-align:right;padding-right:20px;padding-top:10px;">
        <input name="deletechecked" type="submit" id="deletechecked" value="Delete Checked">
        </form>
    </div>

Link to comment
Share on other sites

PHP =  server side language (executed on server before page is delivered to client)

javascript = client side language (executed after client receives page)

 

When you see the confirm box, your records are already deleted. (you can check this by submitting the form, then checking directly in database before you click on 'confirm' or 'cancel').

 

What you need to do is put your javascript inside a function, and place it in the <head> section of your document, call it from the submit button, with onsubmit="", and count the number of checked boxes inside javascript.

then if they click cancel, the page just stays where it is and nothing is posted, otherwise it's posted.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.