遇到代码问题 - 从数据库中删除记录 - JS / PHP

时间:2014-05-08 04:19:36

标签: javascript php mysql

我在使用这段代码时遇到了一些问题,确切地指出了问题的来源,我不确定javascript是否存在问题,但是当我从select.php中选择一条记录时,它最终会停滞不前。 (没有任何反应; /)

confirmDelete.js

function fnConfirm(delUrl) {
if (confirm("Are you sure you want to delete this record?")) {
window.location = delUrl;
}

var linkDel = document.getElementById("linkDelete");

linkDel.onclick= fnConfirm;

select.php

<?php header("Cache-Control:no-cache"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Delete Cabin -AdminPanel</title>
  <link rel="stylesheet" type="text/css" href="stylesheet.css" />
</head>

<body>
  <script src="confirmDelete.js"></script>
  <h2>Select from the cabins listed below to delete:</h2>

  <?php

    //connect to server and database
     include 'sqldb_connect.inc.php';

    //set up query
    $query = "SELECT * FROM tblCabins";

     //execute query
    $result = mysql_query($query);

    if(!$result)
    {
        mysql_close();
        exit("Error retrieving cabins from database");
    }

    //get the number of rows in the cabins table and store in a variable
    if(mysql_num_rows($result) <1)
    {
        mysql_close();
        exit("No cabin entries found");
    }

    //start table
  ?>
<!--.......................................................................-->
    <table>
        <tr>
            <th>cabinID</th>
            <th>Cabin Type</th>
            <th>Cabin Description</th>
            <th>Price per night</th>
            <th>Price per week</th>
            <th>Photo</th>
            <th>&nbsp;</th>
        </tr>
<!--.......................................................................-->
  <?php

        //fetch the next row (or record) of the result set until there are no more left
        while($row = mysql_fetch_array($result))
        {
            //store the results in variables
            $cabinID = $row['cabinID'];
            $cabintype = $row['cabinType'];
            $cabindesc = $row['cabinDescription'];
            $pricepern = $row['pricePerNight'];
            $priceperw = $row['pricePerWeek'];
            $photo = $row['PHOTO'];
  ?>
<!--.......................................................................-->
            <tr>
                <td><?= $cabinID; ?></td>
                <td><?= $cabintype; ?></td>
                <td><?= $cabindesc; ?></td>
                <td><?= $pricepern; ?></td>
                <td><?= $priceperw; ?></td>
                <td><?= $photo; ?></td>
                <td><a id="linkDelete" href="javascript:fnConfirm('cabinDelete_process.php?cabinID=<?= "$cabinID"; ?>')">Delete</a></td>
            </tr>
<!--.................................................................................-->        
  <?php 
        }
        mysql_close(); 
  ?>
<!--.................................................................................-->  
    </table>  

</body>
</html>

process.php

<?php header("Cache-Control:no-cache"); ?>

<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>deleteCabinProcess - adminPanel</title>
    <link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>

<body>
  <?php
        //this page will delete the cabin 
        //selected from the previous page

        //read cabinID passed to this page
        $cabinID = $_GET['cabinID'];

        //connect to server and database
        include 'sqldb_connect.inc.php';

        //set up query
        $query = "DELETE FROM tblCabins WHERE cabinID = '$cabinID'";

        //execute query
        $result = mysql_query($query);

        if(!$result)
        {
            mysql_close();
            exit("Error deleting Cabin from the database");
        }

        mysql_close();
        exit ("Successfully deleted the record from the database ");    
  ?>

</body>
</html>

如果有人能看到任何问题,我们将非常感激.. Brb需要到外面调整我的眼睛!

0 个答案:

没有答案
相关问题