将数据从html id属性传输到php变量方法get

时间:2019-07-17 07:41:05

标签: php html attributes

看了一堆例子。什么都没发生。我尝试将其转换为输入元素ID的值。来自数据库的行标识符,用于随后删除记录。但是无论我如何尝试,Get都不会从id属性中获取此值

<?php
        require_once("dbcontroller.php");
        $db_handle = new DBController();
        $sql = "SELECT * from main";
        $faq = $db_handle->runQuery($sql);
?>

<table class="one">
      <thead>
          <tr>
            <th class="table-header" width="10%">№</th>
            <th class="table-header">Дата</th>
            <th class="table-header">Адрес</th>
            <th class="table-header" width="10%">Наименование проекта</th>
            <th class="table-header">Что изменено</th>
            <th class="table-header">Кем</th>
            <th class="table-header">Документ</th>
          </tr>
      </thead>
      <tbody>
      <?php
      foreach($faq as $k=>$v) {


      ?> 

          <tr class="table-row">
            <td><?php echo $k+1; ?></td>
            <td contenteditable="true" onBlur="saveToDatabase(this,'destination','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $faq[$k]["destination"]; ?></td>
            <td contenteditable="true" onBlur="saveToDatabase(this,'name_change','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $faq[$k]["name_change"]; ?></td>
            <td contenteditable="true" onBlur="saveToDatabase(this,'changee','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $faq[$k]["changee"]; ?></td>
            <td contenteditable="true" onBlur="saveToDatabase(this,'date_change','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $faq[$k]["date_change"]; ?></td>
            <td contenteditable="true" onBlur="saveToDatabase(this,'moderator','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $faq[$k]["moderator"]; ?></td>
            <td contenteditable="true" onBlur="saveToDatabase(this,'image1','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $faq[$k]["image1"]; ?></td>
            <td> <input type="submit" name="delete" value="Delete" onclick="location.href='delete.php'" id=''<?php echo $faq[$k]["id"]; ?>''></td>
            </tr>
    <?php
    }
    ?>
      </tbody>
    </table>

这是关于这行的一切

<td> <input type="submit" name="delete" value="Delete" onclick="location.href='delete.php'" id=''<?php echo $faq[$k]["id"]; ?>''></td>

delete.php

<?php
        $id = $_GET['id'];

        //Connect DB
        //Create query based on the ID passed from you table
        //query : delete where Staff_id = $id
        // on success delete : redirect the page to original page using header() method
        $dbname = "registration_change";
        $conn = mysqli_connect("10.191.24.99", "asutp", "asutp", $dbname);
        // Check connection
        if (!$conn) {
            die("Connection failed: " . mysqli_connect_error());
        }

        // sql to delete a record
        $sql = "DELETE FROM main WHERE id = $id"; 
        echo($sql);
        if (mysqli_query($conn, $sql)) {
            mysqli_close($conn);
            header('Location: main-edit.php'); //If book.php is your main page where you list your all records
            exit;
        } else {
            echo "Error deleting record";
        }
?>

1 个答案:

答案 0 :(得分:1)

只需将id传递到url:

socket.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);

请注意,您在date.timezone=Asia/Jakarta中添加了多余的单引号,我在示例中将其删除了