dongxiao_0528 2015-02-04 15:06
浏览 45
已采纳

尝试使用pdo语句删除行,其中行项匹配php变量

I am trying to receive text input and store it as a variable. Then I use PDO to execute a query that deletes a row from a MySQL database that contains text that matches the text stored in the variable. Obviously this is not working. My usual suspect is my query. I have also been toying with binding params but that didn't work either.

 <?php
     if (isset($_POST['gigDate'])){

            $gigDate  = $_POST['gigDate'];

               if (!empty($gigDate)){

                   require_once("dbconnect.php");
                   $query = $connect->prepare("DELETE * FROM 'gigs' WHERE 'date'='".$gigDate."'");
                   $query->execute(); 

                   }
               else 
                    {
                       echo "failure";
                      }
               require_once('gui.php');
                }
   ?>

This is my html form

   <h3>Delete a gig by date. (copy and paste gig date)</h3>

   <?php include ("gigDelete.php");?>

   <form action="gigDelete.php" method="post">
   <input type="text" name="gigDate"></input>
   <button type="submit" value="Delete" name="Delete">delete gig</button>
   </form>

I have had one error message that stated that my error reporting wasn't working. haha. So I removed it. I only just learned PDO last week and I am unsure if it is appropriate for this task.. How my inexperience shines!

This is the last part of my first ever php GUI. I can upload to the database just dandy and I am displaying the data in a html table which is also working. So I can assume I'm connecting to the db.

  • 写回答

3条回答 默认 最新

  • drgdn82648 2015-02-04 15:09
    关注

    Try this way, why you are using extra single quotes for table and column names? The identifier quote character is the backtick (`)

    DELETE FROM  `gigs` WHERE date='".$gigDate."'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路