note 55791 added to function.is-numeric

From: Date: Sat, 13 Aug 2005 09:38:45 +0000
Subject: note 55791 added to function.is-numeric
Groups: php.notes 
Request: Send a blank email to php-notes+get-93548@lists.php.net to get a copy of this message
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.'); } } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.is-numeric.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55791 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55791&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55791&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55791&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55791&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55791&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55791&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55791&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#93548) next »