Jump to content

Recommended Posts

I am running a community site and I experience a lot of fake registrations and every day i have to clean up and delete a lot of

incomplete user id's from the database. I can tell which users are fake by looking at the country value, because thats the first input box on registration page number 2 , which the spam bot or user never completed. So if the "f4_country" is "0" then I know that this profile registration was never completed and thus can be deleted.

 

So I have made a SQL command that I run from phpmyadmin that deletes the incomplete userid's from two tables... but instead I would like to make a php script that I can run from the admin website or put inside a cron job.

 

Here is the sql command that will be executed :

 

DELETE `dsb_user_accounts`, `dsb_user_profiles` FROM `dsb_user_accounts` INNER JOIN `dsb_user_profiles` ON `dsb_user_accounts`.`user_id` = `dsb_user_profiles`.`fk_user_id` WHERE
`dsb_user_profiles`.`f4_country` = 0
 
Unfortunately I dont know much about php but so far I have figured out that the php file may start like this:
 
<?php
session_start();
$host="localhost";
$db_username="etano";
$db_password="Jgc534S";

$db_name="etano";

mysql_connect($host,$db_username,$db_password);
mysql_select_db($db_name);

$query=("DELETE.................

but then I am stuck ....can I use exact the same sql statements that I used in phpmyadmin or is the syntax in php different ?

it would be nice to get some output from the script too, for example.....n number of rows deleted or something...

 

 

Thanks for any help

 

 

-Utah

 

 

 

 

You can use mysql_query() to send a SQL command to mysql.

eg:

$sql = "delete from..........................";
mysql_query($sql); 

or

mysql_query("delete from ...........................");

You can check this for more infomation: http://www.php.net/mysql_query

Dont use mysql_*. Mysql is deprecated as of 5.3.0 or someting and will not be supported in the future. Use either mysqli() or PDO_mysql(). You can use the exact same queries you would use in PMA.

 

As for getting how many rows were affected, they all have different methods to get that info. Search for it on google, they all have it built in (even mysql()).

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.