utah Posted May 31, 2013 Share Posted May 31, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/278629-need-to-put-a-sql-command-inside-a-php-file/ Share on other sites More sharing options...
roving_php Posted May 31, 2013 Share Posted May 31, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/278629-need-to-put-a-sql-command-inside-a-php-file/#findComment-1433359 Share on other sites More sharing options...
DaveyK Posted May 31, 2013 Share Posted May 31, 2013 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()). Quote Link to comment https://forums.phpfreaks.com/topic/278629-need-to-put-a-sql-command-inside-a-php-file/#findComment-1433368 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.