How to delete a single-quote record from Mysql via PHP?

0
<?php

require 'conn.php';

$del_cidade = mysql_real_escape_string($_POST['del_cidade']);
$pop = mysql_real_escape_string($_POST['l_pop']);

$excluir = mysql_query("DELETE FROM pops WHERE pop = '$pop' AND cidade_id = '$del_cidade'");

sleep(1);
header("Location:painel_adm.php");

?>

I entered through PHP the following record "Water Box Pop" (with single quotation marks), I was able to do this by escaping the characters with mysql_real_escape_string. Now I need to delete this record, but mysql_real_escape_string is not working to delete. How can I do this?

    
asked by anonymous 05.12.2018 / 19:29

1 answer

0

You must first pass both mysql_real_escape_string and Delete over the connection

conn.php

$conn = mysql_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);

if (!$conn) {
    die("Connection failed: " . mysql_connect_error());
}

mysql_set_charset($conn, 'utf8');

delete.php

require 'conn.php';

    $del_cidade = mysql_real_escape_string($conn, $_POST['del_cidade']);
    $pop = mysql_real_escape_string($conn, $_POST['l_pop']);

    $excluir = mysql_query($conn, "DELETE FROM pops WHERE pop = '$pop' AND cidade_id = '$del_cidade'");

    sleep(1);
    header("Location:painel_adm.php");
    
05.12.2018 / 20:16