×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Delete not working

Delete not working

Delete not working

(OP)
I have tried about 15 different ways to delete a record yet this code does not delete but also does not throw an error.

CODE

if ($_GET['pg']=="staff" && $_GET['rec']=="x_del"){
    $id_to_delete = $_GET['id'];
    $sql = "DELETE FROM `Employees` WHERE `idEmployees` =  :idEmployees";
    $stmt = $pdo->prepare($sql);
    //echo $id_to_delete;
    $stmt->execute( array( ":id_to_delete" => $id_to_delete ) );
    //$stmt->bindParam(':idEmployees', $_Get['id'], PDO::PARAM_INT);   
    //$stmt->execute();
} 

What am I doing wrong here?

RE: Delete not working

Your Array is referencing a parameter that does not exist in your query.

CODE

if ($_GET['pg']=="staff" && $_GET['rec']=="x_del"){
    $id_to_delete = $_GET['id'];
    $sql = "DELETE FROM `Employees` WHERE `idEmployees` =  :idEmployees";
    $stmt = $pdo->prepare($sql);
    //echo $id_to_delete;
    $stmt->execute( array( ":id_to_delete" => $id_to_delete ) );
    //$stmt->bindParam(':idEmployees', $_Get['id'], PDO::PARAM_INT);   
    //$stmt->execute();
} 
Your bindParam attempt was also wrong, because in PHP variable names are case sensitive. so $_GET is not the same as $_Get.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

RE: Delete not working

(OP)
I changed the $_GET and it worked! I am missing simple things.

Maybe you can help me out again :) I decided to change the table I was working with and started with copying the code to modify. I have a query that had 2 params to get the recordset, nothing is coming back from the db. I removed both params and still get no results with...

CODE

$ps2 = $pdo->prepare("SELECT * FROM Schedule2");
$ps2->execute();
$results = $ps2->rowCount();  
echo "RESULTS=" . $ps2->rowCount(); 

There is currently 1 record in there. Why am I not getting a result of 1?

RE: Delete not working

From the PHP online manual(http://php.net/manual/en/pdostatement.rowcount.php):

Quote (PHP.com)


PDOStatement::rowCount() returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement executed by the corresponding PDOStatement object.

If the last SQL statement executed by the associated PDOStatement was a SELECT statement, some databases may return the number of rows returned by that statement. However, this behaviour is not guaranteed for all databases and should not be relied on for portable applications.

Your DB may simply not be returning the number of rows.

Other than that, try checking if the query is returning any errors:

CODE

$ps2 = $pdo->prepare("SELECT * FROM Schedule2");
$ps2->execute();
echo "<pre>" . print_r($ps2->errorInfo(),1) . "</pre>";
$results = $ps2->rowCount();  
echo "RESULTS=" . $ps2->rowCount(); 



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close