Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Can't remove row from db
Hello, I have this code
$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
$email = $_POST['emailRemove'];
$res = $mysqli->query("DELETE FROM users WHERE email = $email");
if ($mysqli->affected_rows) {
echo "removed!";
}
but the record is always there. Anybody can hint where I’m wrong?
It’s a code I’m putting right within an article…
Thanks!
Last edited by Manaus (2012-03-15 13:43:54)
Offline
Re: Can't remove row from db
Manaus wrote:
Anybody can hint where I’m wrong?
Your table name is wrong for a start (it should be txp_users
). Also you’re not sanitizing the input, which is dangerous. And since a connection to the database already exists, you can use the core functions to your advantage:
$email = doSlash(ps('emailRemove'));
$res = safe_delete('txp_users', "email='$email'");
if ($res) {
echo "removed!";
}
Try that and see how you get on.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Can't remove row from db
It works!! Thanks Bloke
Offline
Pages: 1