0

每次用户插入信息并单击添加按钮时,新数据将存储到数据库并回显到该表中

桌子

<tr>
    <td colspan="4" align="right">
        <input  type="image" value="image"  src="images/btn_add.gif" onclick="action_1()">
    </td>
</tr>
<tr>
    <td colspan="2" class="title_all_u">Family Member Summary</td>
</tr>
<tr>
    <td>
        <?php 
            $query = "SELECT * FROM family_child WHERE LAS_login_id = ($emp_id)";
            $result = mysql_query($query) or die(mysql_error());
            echo "<table border='1'>
                    <tr>
                        <th>Family Type</th>
                        <th>Name</th>
                    </tr>";
                while($row = mysql_fetch_array($result))
                {
                echo "<tr>";
                echo "<td>" . $row['family_child_type'] . "</td>";
                echo "<td>" . $row['family_child_name'] . "</td>";
                echo "</tr>";
                }
            echo "</table>";
        ?>
    </td>           
</tr>   

这是插入查询

if ( $action ==3 ) {
   $spouse_type = $_POST['spouse_type'];
   $spouse_name = $_POST['spouse_name'];

   $sql1 = "INSERT INTO family_spouse (LAS_login_id, spouse_type, spouse_name)  VALUES ('$LAS_login_id', '".strtoupper($spouse_type)."','".strtoupper($spouse_name)."')";

这 2 个代码用于插入数据库并在页面中回显。如何echo "<td>" . $row['family_child_name'] . "</td>";为我回显的每一行添加删除按钮,以便用户可以删除显示表中的错误行。

4

3 回答 3

0
echo "<td>" . $row['family_child_name'] . " <a href='page.php&action=delete&id=family_name_id'>Delete</a></td>

然后在您的页面中获取(如果操作 == 删除)> 执行您的查询以删除 ID 是家庭子名称表的 ID 的行。

于 2013-10-11T08:02:14.023 回答
0

这种编码工作完美。我在我的电脑上试过并在这里发布了这段代码。当您插入新记录时,它将自动插入删除按钮。然后,如果您单击删除按钮,它将删除 mysql db 中的行详细信息..

 <body>
    <?
     echo "<tr>
            <td>";
               // your database connection
               // select database
                    $query = ("SELECT * FROM family_child");
                    $result = mysql_query($query) or die(mysql_error());
                    echo "<table border=1>
                            <tr>
                                <th>Family Type</th>
                                <th>Name</th>
                                <th>Delete Record</th>
                            </tr>";
                        while($row = mysql_fetch_array($result))
                        {
                        echo "<tr>";
                        echo "<td>" . $row['family_child_type'] . "</td>";
                        echo "<td>" . $row['family_child_name'] . "</td>";
                        echo "<td><form method=post>
                        <input name=id type=hidden value='".$row['family_child_name']."';>
                        <input type=submit name=submit value=Delete>
                        </form></td>";
                        echo "</tr>";
                        }
                    echo "</table>";

            echo "</td>           
        </tr>";

       // delete record
    if($_SERVER['REQUEST_METHOD'] == "POST")
    {
    if(isset($_POST['id']))
    {
    $id = mysql_real_escape_string($_POST['id']);
    $sql = mysql_query("DELETE FROM family_child WHERE family_child_name ='$id'");
    if(!$sql)
    {
        echo ("Could not delete rows" .mysql_error());
    }
    }
    }
    ?>
于 2013-10-11T10:04:28.253 回答
0
$query = "SELECT * FROM family_child WHERE LAS_login_id = ($emp_id)";
$result = mysql_query($query) or die(mysql_error());
        echo "<table border='1'>
                <tr>
                    <th>Family Type</th>
                    <th>Name</th>
                    <th>Action</th>
                </tr>";     

    while($row = mysql_fetch_array($result))
    {
    echo "<tr>
    <td>" . $row['family_child_type'] . "</td>
    <td>" . $row['family_child_name'] . "</td>
    <td>
        <a href='../path/process.php?action=delete&id=".$row['family_child_id']."'>
        DELETE RECORD
        </a>    
    </td>
    </tr>";
    }
    echo "</table>";
    ?>

在进程页面上检查操作 = 删除并编写删除查询 family_child_id = 根据您的表详细信息更改表的主键

编辑

过程页面:

if($_GET["action"] == "delete")
{
    $sql3="DELETE FROM family_child WHERE LAS_login_id =".$_GET["LAS_login_id"]; 
    $result3 = mysql_query($sql3);

    if (mysql_affected_rows() > 0) 
    {
        header("location:dashboard.php?tab=1");
    }
}
于 2013-10-11T08:05:58.040 回答