Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-03-15 13:43:04

Manaus
Member
From: Turin, Italy
Registered: 2010-10-22
Posts: 251
Website

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

#2 2012-03-15 14:08:58

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,392
Website GitHub

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

#3 2012-03-15 14:32:13

Manaus
Member
From: Turin, Italy
Registered: 2010-10-22
Posts: 251
Website

Re: Can't remove row from db

It works!! Thanks Bloke

Offline

Board footer

Powered by FluxBB