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条)

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址