note 84843 added to function.mysql-affected-rows

From: Date: Fri, 01 Aug 2008 16:06:25 +0000
Subject: note 84843 added to function.mysql-affected-rows
Groups: php.notes 
Request: Send a blank email to php-notes+get-143012@lists.php.net to get a copy of this message
Some users may use this method for CMS systems. Below is an example of a password change function. It can be very useful as it: 1. Is secure from hacks 2. Checks for the user by username and password 3. Displays error message if user dosn't exist _________________________________________________ <? $new = "$_POST[new]"; $old = "$_POST[old]"; $username = "$_POST[username]"; $table = "admins"; include_once "../config/config.inc.php"; $con = mysql_connect("$server","$username","$password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("$database", $con); $new1 = mysql_real_escape_string($new); $old1 = mysql_real_escape_string($old); $user = mysql_real_escape_string($username); $query = "UPDATE $table SET password = '$new1' WHERE password = '$old1' AND username = '$user'"; $result = mysql_query($query);; if (mysql_affected_rows() <= 0) echo "We couldn't find the account to change in our records" } else { echo "Password Changed Successfully"; } mysql_close($con); ?> ---- Server IP: 87.124.64.96 Probable Submitter: 89.240.43.175 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-affected-rows.php Edit -- https://master.php.net/note/edit/84843 Del: integrated -- https://master.php.net/note/delete/84843/integrated Del: useless -- https://master.php.net/note/delete/84843/useless Del: bad code -- https://master.php.net/note/delete/84843/bad+code Del: spam -- https://master.php.net/note/delete/84843/spam Del: non-english -- https://master.php.net/note/delete/84843/non-english Del: in docs -- https://master.php.net/note/delete/84843/in+docs Del: other reasons-- https://master.php.net/note/delete/84843 Reject -- https://master.php.net/note/reject/84843 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#143012) next »