I have been trying to delete a row from my data base but it keep showing me deleted without deleting anything please can someone figure out what the problem is with my codes
I have tried using PDO and mysql but is not deleting but will show deleted I don't know what to do again.
MYSQL
if($user == $me){
$sql_delete = "DELETE FROM replys WHERE id = '$id' AND rusername = '$me'";
echo $sql_delete;
mysql_query($sql_delete) or die(mysql_error());
echo "Deleted";
}
else{
}
}
?>
PDO
<?php
session_start();
if(isset($_POST['DeleteThis'])){
$db_host = "localhost";
$db_user = "root";
$db_pass = "kindom";
$db_name = "posters";
try {
$user = $_SESSION['username'];
$form = $_POST;
$id = $form['id']);
$me = $form['me'];
if($me == $user){
$db_conn = new PDO("mysql:host={$db_host};dbname={$db_name}",$db_user,$db_pass);
$db_conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $db_conn->prepare("DELETE FROM replys WHERE id = :id AND rusername = :user");
//I have tried using this SQL statements
//$query = "DELETE FROM replys WHERE id = {$id} AND rusername = {$user}";
//$query = "DELETE * FROM replys WHERE id = :id AND rusername = :rusername";
$query = "DELETE FROM replys WHERE id = :id AND rusername = :rusername";
$stmt->bindParam(':id', $id);
$stmt->bindParam(':rusername', $user);
$stmt->execute();
echo "Deleted";
}
else{
//Do nothing
}
}
catch(PDOException $e)
{
echo "Error:" . $e->getMessage();
}
$db_conn = null;
}
?>
HTML
<a href="javascript:void(0);" onclick="document.getElementById('deleterp').submit();"><i style="font-size:17px;color:#F00;" class="fa fa-trash"></i></a>
<form id="deleterp" action="" method="POST">
<input type="hidden" name="id" value="<?php echo $rpId;?>"/>
<input type="hidden" name="DeleteThis" value="1"/>
<input type="hidden" name="me" value="<?php echo $rplyuser;?>"/>
</form></div>