Link to home
Start Free TrialLog in
Avatar of Ryan Bayne
Ryan BayneFlag for United Kingdom of Great Britain and Northern Ireland

asked on

MySQL Argument in Query - Before or Equal to current date

Hey

I've never done this before. I'm trying to use an SQL query that has an argument. The aim is to retrieve all records from a table that holds a set of scheduled account deletions, where the scheduled date is equal to or before the current date.

Then delete those records. However so far nothing seems to happen. No records are deleted and no errors.

So how should I really be doing this?

Thanks all
elseif($service == "process")//Display form for creating new parent catagory
	{
		//get todays date
		$today = date("m.d.y"); 
 
		//Get data for accounts to be deleted
		$sql1 = mysql_query("SELECT * FROM deleteaccount WHERE delDATE <= '$today'");
		if (!$sql1)
		{
			die('Query execution problem getting accounts awaiting deletion: ' . mysql_error());
		}
		else
		{
			//put the found member ids for deletion into variable then delete their account
			while ($row = mysql_fetch_array($sql1, MYSQL_ASSOC))
			{	
				$owner = $row['delOWNER'];
				//delete the user entry with the id matching $owner
				$sql2 = mysql_query("DELETE FROM memb_userlist WHERE user_id = '$owner'");
				if (!$sql2) 
				{
					die('Query execution problem while deleting a members account: ' . mysql_error());
				}
				else
				{
					//remove the deletion entry from deleteaccount table
					$sql3 = mysql_query("DELETE FROM deleteaccount WHERE delOWNER = '$owner'");
				}
			}
			echo "<h3>All scheduled account have been deleted as requested</h3>";
		}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of dqmq
dqmq
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ryan Bayne

ASKER

Great thanks a lot