dongyongan9941 2017-03-11 19:49
浏览 43

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

I Use the following code for deleting a particular row from but does not work properly. I have two files one brand.php and delete.php. Here are the codes. How do I delete the particular row from db. enter image description here enter image description here

brand.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

$Rowid=$_GET['rid'];
    $sql = "http://www.query.mydomain.com/default.aspx?dbname=" . $GLOBALS    ['strDB'] . "&query=Delete From sp_DelBrand Where Code = ".$Rowid."";
    $sqlquery = str_replace ( " ", "%20", $sql );
    $json = file_get_contents ( $sqlquery );
    $data = json_decode ( $json, TRUE );
    $resultID;
    $Result1 = ' ';
    foreach ( $data as $item ) {
        $Result1 = $item ['Result'];
        $resultID = $item ['ResultId'];
    }
    foreach($data as $item)
        {
            $Result1 = $item['Result'];
            $resultID = $item['ResultId'];
        }
    echo '<script type="text/javascript">';
    echo 'alert("'.$Result1.'");';
    echo '</script>';
    if (!isset($Result1))
        {
            echo '<script type="text/javascript">window.history.go(-1);</script>';
        }
    else
        {
            echo '<script type="text/javascript">window.history.go(-1);</script>';
        }   
}
?>

After Clicking Deleting Icon there is no sign of redirecting to delete.php?id=rowid, but the page loads and comeback brand.php and the row record is not deleted, whats wrong with me!!

  • 写回答

1条回答 默认 最新

  • duanque2413 2017-03-11 20:29
    关注

    This is PDO connection and Query for delete row:

    <?php
    
    $id = 5;
    
    $dbh = new PDO('mysql:host=localhost;dbname=deletelimit10', "root", "");
    
    $query = $dbh->query("DELETE FROM content WHERE id = '$id'"); // Run your query
    
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助