Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete not working

Status
Not open for further replies.

LWolf

Programmer
Feb 3, 2008
77
0
0
US
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?
 
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` =  [b]:idEmployees[/b]";
    $stmt = $pdo->prepare($sql);
    //echo $id_to_delete;
    $stmt->execute( array( "[b]:id_to_delete[/b]" => $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
 
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?
 
From the PHP online manual(
PHP.com said:
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:
[COLOR=#BABDB6]$ps2 = $pdo->prepare("SELECT * FROM Schedule2");
$ps2->execute();[/color]
[b]echo "<pre>" . print_r($ps2->errorInfo(),1) . "</pre>";[/b]
[COLOR=#BABDB6]$results = $ps2->rowCount();  
echo "RESULTS=" . $ps2->rowCount();[/color]





----------------------------------
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top