Jump to content

DB


shage

Recommended Posts

			$query = "INSERT INTO ".MYSQL_TBL_MAILLIST_BLACKLIST." VALUES ('$email')";
                        $query = "DELETE FROM ".MYSQL_TBL_MAILLIST_SUBSCRIBERS." WHERE address = '$email' AND userkey = '$key'";
		$result = mysql_query($query) or die("Query failed : " . mysql_error());

 

why is it not adding the email addresse that is pulled to the db,hmmm

Link to comment
https://forums.phpfreaks.com/topic/58115-db/
Share on other sites

Well the problem is only the last query is being run. The first query will never be run as the second query is overriding it as you are reassigning the $query variable a new value - which is the second query.

 

In order for SQL queries to be ran you must run them with the mysql_query function. Just defining the query within a variable on it's own wont do anything as PHP sees the $query variable holding a string. PHP wont see it as an MySQL query and run that query through MySQL.

 

This is what your code should be:

<?php

// run the first query which inserts the email addy into the blacklist
$query1 = "INSERT INTO ".MYSQL_TBL_MAILLIST_BLACKLIST." VALUES ('$email')";
$result1 = mysql_query($query1) or die("Query1 failed : " . mysql_error());

// now we ckeck to see if the query ran successfully
// if it did we'll run the second query
if($result1)
{
    $query2 = "DELETE FROM ".MYSQL_TBL_MAILLIST_SUBSCRIBERS." WHERE address = '$email' AND userkey = '$key'";
    $result2 = mysql_query($query) or die("Query2 failed : " . mysql_error());

   // rest of code here
}
else
{
    // do something else
}

?>

Link to comment
https://forums.phpfreaks.com/topic/58115-db/#findComment-288232
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.