编辑和删除数据库中不包含存储过程的特定行

时间:2017-03-11 19:49:41

标签: php mysql

我使用以下代码删除特定行但无法正常工作。我有两个文件,一个是brand.php和delete.php。这是代码。如何从db中删除特定行。 enter image description here enter image description here

brand.php

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showFinal" {
    let lastVC = segue.destination as! TestingViewController
    lastVC.imageDisplay = self.finalImage
}

delete.php

$sql = "http://www.query.mydomain.com/default.aspx?dbname=compname_dbName&query=select Code, Id, Name from Brand where CompanyCode = 87";
$sqlquery = str_replace ( " ", "%20", $sql );
$json = file_get_contents ( $sqlquery );
$data = json_decode ( $json, TRUE );
$result = array ();
$i = 1;
foreach ( $data as $item ) {
    $Rowid = $item ['Code'];
    $BId = $item ['Id'];
    $BName = $item ['Name'];
    ?>
        <form method = "post" action = "">      
            <tbody>
            <tr>
            <td> <?php echo $Rowid; ?> </td>
            <td><?php echo $BId; ?> </td>
            <td><?php echo $BName; ?> </td>
            <td><p data-placement="top" data-toggle="tooltip" title="Edit">
<button class="btn btn-primary btn-xs" data-title="Edit" data-toggle="modal" data-target="#edit">
            <span class="glyphicon glyphicon-pencil"></span>
            </button>
        </p></td>
        <td><p data-placement="top" data-toggle="tooltip" title="Delete">
        <a href="delete.php?rid=<?php echo $Rowid; ?>"><button type="submit" id="rid" name="rid" class="btn btn-danger btn-xs">
            <span class="glyphicon glyphicon-trash"></span></button></a>
            </p></td>
        </tr>
    </tbody>
        </form>
    <?php $i++; } ?>
    </table>

点击删除图标后没有重定向到delete.php?id = rowid的迹象,但页面加载并回归brand.php并且行记录没有被删除,我错了!!

1 个答案:

答案 0 :(得分:0)

这是PDO连接和查询删除行:

<?php

$id = 5;

$dbh = new PDO('mysql:host=localhost;dbname=deletelimit10', "root", "");

$query = $dbh->query("DELETE FROM content WHERE id = '$id'"); // Run your query

?>