thempower Posted July 17, 2012 Share Posted July 17, 2012 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); ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 17, 2012 Share Posted July 17, 2012 Rather than actually deleting the records, have a column with their account status (0=inactive, 1=active) and update that. One query. Quote Link to comment Share on other sites More sharing options...
thempower Posted July 17, 2012 Author Share Posted July 17, 2012 That's right but we are talking about 2500 users so I want to delete them. (And my ban system works with 0=inactive, 1=active ) Thank you for your answer Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 17, 2012 Share Posted July 17, 2012 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. Quote Link to comment Share on other sites More sharing options...
thempower Posted July 17, 2012 Author Share Posted July 17, 2012 Oh yea the problem is that only the records in the table "emailactivatie" is deleted after running the script and not the records in the users table. What means that I do something wrong. It gives no errors. Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 17, 2012 Share Posted July 17, 2012 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. Quote Link to comment Share on other sites More sharing options...
thempower Posted July 17, 2012 Author Share Posted July 17, 2012 I have already tried it 10 times and I never see an error. And will it be able to delete the 2 records with a join ? Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 18, 2012 Share Posted July 18, 2012 You don't see an error because you're not checking for an error. mysql_query mysql_error Have you TRIED with a join? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.