PHP SQL delete not working? No clue what's wrong.

Why in the world won’t this work :confused: I don’t have people to go to for simple questions like this so I apologize.

[php]<?php
if (isset($_GET[‘e’])) {

include_once "connect_to_mysql.php";
$email = $_GET['e'];

$sql_delete = mysql_query("DELETE FROM wp_newsman_lst_nickd WHERE email='$email' LIMIT 1");

if (!$sql_delete) {
	echo "Sorry there seems to be trouble removing your listing. Please email Admin directly using this email address: ***";
} else {
	echo "It is done. You will not receive our newsletter ever again unless you relist.";
}

}
?>[/php]

First, don’t use mysql_ functions.

Next, since this is a WordPress site, look at how WordPress interacts with the database.

Try to use wordpress default query and database connection structure…

or else try below code :–

$post_id = $post->ID; // or use Your custom post id ex. $post_id = 2;

$wpdb->query($wpdb->prepare(“DELETE FROM $wpdb->newsman_lst_nickd WHERE $wpdb->newsman_lst_nickd.email = $email”,$post_id));

LIMIT 1 remove it from the query and then try

Change your code to MySQLi (improved MySQL). And I would say the “LIMIT” is causing the trouble.

also, you don’t seem to refer to a database_name. I can see you make a connection to your database. Also I can see you tell the SELECT statement where to delete the row, but you don’t seem to tell where to find it.

For example. My accountname = 1234. So my connection will connect to DB1234. Inside my account I have several databases. Like DB1234_login, DB1234_messageboard, etc. Within these database I have several tables. So INSIDE DB1234_login I have a table called, users, loginAttemps, etc.

So this would look like:

  • DB1234
    • DB1234_login
      • users
      • loginAttemps
        -DB1234_messageboard

You seem to create a connection to DB1234, you also tell to delete a row from users but you don’t tell in your script that this users can be found inside DB1234_login.

I hope this makes sense to you and, off course, solves the problem :smiley:

Sponsor our Newsletter | Privacy Policy | Terms of Service