How to delete record with simple Mysql quotes via PHP?

Asked

Viewed 56 times

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 inserted through PHP the following record "Pop Water Box" (with simple quotes), I managed to do this by escaping the characters with the mysql_real_escape_string. Now I need to delete this record, but the mysql_real_escape_string is not working to delete. How can I do this?

  • And why not insert without quotation marks, but print them only when necessary? Have you tried "'Hello'" OR "'Hello'?'"

1 answer

0

First you must pass both the mysql_real_escape_string and Delete through 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");

Browser other questions tagged

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