从上一页的表中添加/删除数据

时间:2015-01-04 05:20:44

标签: php html mysql

我有一个从PHP数据显示的HTML表格,我试图根据点击的内容将数据从一个表格移动到另一个表格。我不能让它从一个表移动到另一个表但我没有得到任何代码错误。

<html>
<head>
<title>View Requests</title>
</head>
<body>
<div class="breadcrumbs">
<center>
<a href="../index.php">Home</a> &middot; <a href="../controlpanel/requests">Requests</a>
</center>
</div>

<?php
require_once '../../scripts/app_config.php';
require_once '../../scripts/database_connection.php';

// get results from database
$result = mysql_query("SELECT * FROM temp")
or die(mysql_error());

echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th>Username</th> <th></th> <th></th></tr>";

// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array( $result )) {

    // echo out the contents of each row into a table
    echo "<tr>";
    echo '<td>' . $row['User_id'] . '</td>';
    echo '<td>' . $row['First_name'] . '</td>';
    echo '<td>' . $row['Last_name'] . '</td>';
    echo '<td>' . $row['Username'] . '</td>';
    echo '<td><a href="submit.php?id=' . $row['User_id'] . '">Approve</a></td>';
    echo '<td><a href="delete.php?id=' . $row['id'] . '">Delete</a></td>';
    echo "</tr>";
}
// close table>
echo "</table>";
?>
</body>
</html>

PHP编辑脚本:

  <html>
<head>
<title>View Requests</title>
</head>
<body>
<div class="breadcrumbs">
<center>
<a href="../index.php">Home</a> &middot; <a href="../controlpanel/requests">Requests</a> &middot; <a href="../allusers">All Users</a>
</center>

<?php
require_once '../../scripts/app_config.php';
require_once '../../scripts/database_connection.php';


$id = $_GET['id'];


    $sql = ("INSERT INTO users
    SELECT * FROM temp WHERE User_id = $id ");
    mysql_query($sql)
        or die(mysql_error());


?>




</body>
</html>

1 个答案:

答案 0 :(得分:0)

我需要使用

$id = $_get['id];

并且在insert语句中我必须用User_id替换id

  <html>
    <head>
    <title>View Requests</title>
    </head>
    <body>
    <div class="breadcrumbs">
    <center>
    <a href="../index.php">Home</a> &middot; <a href="../controlpanel/requests">Requests</a> &middot; <a href="../allusers">All Users</a>
    </center>

    <?php
    require_once '../../scripts/app_config.php';
    require_once '../../scripts/database_connection.php';


    $id = $_GET['id'];


        $sql = ("INSERT INTO users
        SELECT * FROM temp WHERE User_id = $id ");
        mysql_query($sql)
            or die(mysql_error());


    ?>




    </body>
    </html>