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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.