note 55791 deleted from function.is-numeric by mazzanet

From: Date: Sat, 13 Aug 2005 09:41:33 +0000
Subject: note 55791 deleted from function.is-numeric by mazzanet
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-93550@lists.php.net to get a copy of this message
Note Submitter: yaggles [AT] gmail [DOT] com Reason: useless ---- Here's a random function for removing a user from a user database. It's quite simple but you'll need to edit some variables to meet your needs. ;) I'm posting it here because it uses the is_numeric function in it to make sure that the user ID is a number. <? function deleteUser($id) { //mysql_connect('server', 'username', 'password'); //mysql_select_db('database'); $id = mysql_real_escape_string($id); if(!is_numeric($id)) { die('<b>Error</b>ID invalid. ID must be numeric.'); } else { $sql = 'DELETE FROM table WHERE id = \'' . $id . '\''; $sql_res = mysql_query($sql); if($sql_res) { //Check to make sure that the record is really not there. Make sure it was really deleted $sql = 'SELECT * FROM users WHERE id = \'' . $id '\''; $result = mysql_query($sql); if(!$result) { //It was! :D echo 'User deleted successfully.'; } else { die('User not deleted. Please try again.'); } } else { die('Could not remove user from database.'); } } } ?>

« previous php.notes (#93550) next »