drbouzlxb92333332 2015-10-07 02:56
浏览 23
已采纳

如何使用Php删除Mysql中的数据[关闭]

hello guys im having a hard time figuring how to delete data in database using php im using MYSQLI because mysql gives me warning i tried so many times but failed here is the code.HERE IS THE PICTURE:PICTURE ERROR

<!DOCTYPE HTML>
<html>
    <head>
    <style>
       .wrap{
           width:800px;
           margin:0px auto;

       }
      form{
          margin-left:200px;


      }
      a,a:visited{
          text-decoration:none;
          color:black;
      }
    </style>    
    </head>
    <body>
    <?php
    require('connect.php');
        if(isset($_POST['Submit'])){
            $sid=$_POST['name'];
            $sql = "DELETE scholars ". "WHERE sid = $sid";
             $retval = $mysqli->query($sql,$mysqli );

            if(!$retval )
            {
               die('Could not delete data: ' . $mysqli->error);
            }

            echo "Deleted data successfully
";

            $mysqli->close( );
         }  



    ?>
    <div class="wrap">
    <form action="dscholar.php" method="POST">
     <table>
        <tr>
        <td>ScholarID:</td> 
        <td><input type="text" name="name" required><td>
        </tr>
        <td><input type="submit" name="Submit" value="Delete Scholar"></td>
        <td><button><a href="index.html">Back to Homepage!</a></button></td>
        </tr>

     </table>
    </form>
    </div>
    </body>
</html>

HERE IS THE CONNECTION

<?php
$mysqli=new mysqli("localhost","root","","dblogin");

?>
  • 写回答

2条回答 默认 最新

  • douwulu2576 2015-10-07 03:00
    关注

    missing FROM in your query

    $sql = "DELETE FROM scholars WHERE sid = '$sid'";
    

    and put variable inside '

    '$sid'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度