DELETE statement does not delete by php but by phpmyadmin the instruction works

Asked

Viewed 68 times

0

I have the following code where I am trying to delete a column from the comic through php :

session_start();
$dbh = new PDO('mysql:host=localhost;dbname=samsic', 'root', '');

$sql = $dbh->prepare("DELETE FROM ferias WHERE id=':i' and idtrabalhador=':it' ");
$sql->bindValue(':i',$_GET['id']);
$sql->bindValue(':it',$_SESSION['id']);
$resultado=$sql->execute();

if($resultado){
    echo "Apagou";
}else{
    echo "não apagou";
}

The code always returns to me "Deleted" but it doesn’t erase anything in the database. On the other hand, if you copy the sql statement I have in php in mysql and replace it with the same values it will work correctly and delete the column.

Someone can help me?

  • I removed the values to be received from the query and it worked

1 answer

4


When you put the single quotes the SQL command starts to consider the value as a VARCHAR, if the type of the tuples is different from VARCHAR or a DATE, an INT for example, the quotation marks should not be placed. When you have any questions about running an SQL just test in the phpmyadmin console itself.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.