回删记录

时间:2014-05-09 18:26:39

标签: php html mysql

所以我试图回显要从index.php中删除的记录的所有字段

我似乎无法获得与记录有关的数据。

这是我的代码

这是删除记录的index.php。

<!DOCTYPE html>
<html>
<?php
        $con=mysqli_connect("localhost","root","","project1");
// Check connection
        if (mysqli_connect_errno())
          {
          echo "Failed to connect to MySQL: " . mysqli_connect_error();
          }
// Query sites table for all records      
$result_sites = mysqli_query($con,"select * from sites");
?>
<head>
<link rel="stylesheet" type="text/css" href="site.css">
<script language="JavaScript" type="text/javascript">
    function checkDelete()
    {
        return confirm('Confirm delete?');
    }
</script>
</head>
<body>
<h1>Site Code Page</h1>
    <p>this website is used to add site codes, search sites codes and delete sites codes</p>
        <h2 class="button"><a href=/index.php>Home</a></h2>
        <h2 class="button"><a href=/insert.php>add site</a></h2> 
        <h2 class="button"><a href=/>search site</a></h2>
<div class="sites_table">
    <?php
        // Draw table of all records within sites table
        echo '<table border="1">
        <tr>
        <th>Site Name</th>
        <th>Site Code</th>
        <th>Address</th>
        <th>City</th>
        <th>Postal Code</th>
        <th>Province</th>
        <th>Country</th>
        <th>Delete Record</th>
        <th>Modify Record</th>
        </tr>';
            while($row = mysqli_fetch_array($result_sites))
            {
                echo '<tr>';
                echo '<td>' . $row['site_name'] . '</td>';
                echo '<td>' . $row['site_code'] . '</td>';
                echo '<td>' . $row['site_address'] . '</td>';
                echo '<td>' . $row['site_city'] . '</td>';
                echo '<td>' . $row['site_postalcode'] . '</td>';
                echo '<td>' . $row['id_province'] . '</td>';
                echo '<td>' . $row['id_country'] . '</td>';
                echo '<td><a href="/delete.php?id=' . $row['id'] . '" onclick="return checkDelete()">delete</a></td>';
                echo '<td><a href="/modify.php?id=' . $row['id'] . '">modify</a></td>';
                echo '</tr>';
            }           
        echo '</table>';
    ?>
</div>
<div class="page_number">
Page ->,    
</div>
</body>
</html>

这是Delete.php文件

<?php
    $con=mysqli_connect("localhost","root","","project1");
        // Check connection
    if (mysqli_connect_errno())
    {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

//Delete Site record from the Sites table   
$sites_id=$_GET['id']; 
    if (isset($_GET['id']))
    { 
    $query = mysqli_query($con, "DELETE FROM sites WHERE ID='$sites_id'");

    echo 'id: ' . $id . ' site_name: ' . $site_name;
    }
?>

感谢您的帮助

0 个答案:

没有答案