Jump to content

Deleting 2 records seperate tables


thempower

Recommended Posts

Hi,

 

I made this script to delete inactive people.

My database looks like this :

 

emailactivatie :

ID----mail----datum----code

 

users :

ID---mail--- .......

 

So if the date of emailactivatie is higher then 7 days my script should delete that record and the one with the same e-mail adresse in users.

 

 

<?php

$link = mysql_connect('***,***,****');
if (!$link) {
    die('Not connected : ' . mysql_error());
}

$db_selected = mysql_select_db('*****', $link);
if (!$db_selected) {
    die ('Can\'t use kevintest : ' . mysql_error());
}
$result = mysql_query("SELECT * FROM emailactivatie WHERE datum < now() - interval 7 day, users.mail ");{
mysql_query("DELETE FROM users WHERE emailactivatie.mail = users.mail ");
mysql_query("DELETE FROM emailactivatie WHERE datum < now() - interval 7 day");
}


mysql_close($link);

?>

Link to comment
https://forums.phpfreaks.com/topic/265826-deleting-2-records-seperate-tables/
Share on other sites

Why do you want to delete them? Generally, you don't delete data like this. It just causes problems later on.

 

Furthermore, you haven't posted what the problem is. As it is, your script should produce syntax errors, and you never do anything with the data you selected.

It's a malformed SQL statement.

DELETE FROM users WHERE emailactivatie.mail = users.mail

That statement will produce an error. You're not checking for errors, or you'd see it.

you can't access the table like that. You could do this with a JOIN.

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.