1

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.

12
  • For one thing, you're using the wrong identifiers for both your table and column. Plus, get rid of the *. Read up on the function => dev.mysql.com/doc/refman/5.0/en/delete.html Commented Feb 4, 2015 at 15:06
  • 1
    What's the point of using prepared statements if you are hardcoding the values? Commented Feb 4, 2015 at 15:06
  • Add $connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); right after the connection is opened and you will see the errors. Commented Feb 4, 2015 at 15:10
  • The * is gone. I should point out that i am not on localhost. The site is live. I received a request to add this delete functionality. So I am uploading to test. Is this bad practice? Commented Feb 4, 2015 at 15:20
  • Is it working from you now, as per the answers given? Most of which are incorrect. Bad practice? Your code is full of syntax errors that I've already pointed out. Have you looked into anything I've said above? Commented Feb 4, 2015 at 15:23

3 Answers 3

1

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."'
Sign up to request clarification or add additional context in comments.

2 Comments

I've didn't even know backticks existed until right now.
nevermind bro, it is enough to know that "Stackoverflow Exists..", ha ha best of luck
1

Try like this:

$query = $connect->prepare("DELETE FROM gigs WHERE date='".$gigDate."'");

Btw, if you are using PDO, there is no good reason to hardcode values like that.

1 Comment

This will fail, being the * in DELETE * FROM
-1

I hope this will work for you:

$query = $connect->prepare("DELETE * FROM 'gigs' WHERE 'date'= :date");
$query->bindParam(':date', $gigDate);
$query->execute(); 

4 Comments

I'll give it a crack.
I tried it and no success. I can assume that the PDO is not the problem.
This will fail for two reasons.
Wrong identifiers dev.mysql.com/doc/refman/5.0/en/identifier-qualifiers.html and not the way to delete dev.mysql.com/doc/refman/5.0/en/delete.html - See the accepted answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.