Fwd: [PHP-NOTES] note 84843 deleted from function.mysql-affected-rows by danbrown

From: Date: Fri, 01 Aug 2008 16:16:57 +0000
Subject: Fwd: [PHP-NOTES] note 84843 deleted from function.mysql-affected-rows by danbrown
References: 1 2  Groups: php.notes 
Request: Send a blank email to php-notes+get-143014@lists.php.net to get a copy of this message
George, I had to reject the code you submitted because of a few simple, but effectual, mistakes in the block. If you'll update the following and resubmit, the code will be welcome to remain attached to the manual: 1.) Do not use short_open_tags code like this: <?. Please use the full <?php. 2.) In lines like this: $old = "$_POST[old]"; it's not necessary to enclose in quotes, but you *should* use quotes within the brackets. For example: $_POST['old'] 3.) Because you're not including the config.php file, simply add a comment like so: // Include config.php for database configuration data. 4.) You have two semicolons here: $result = mysql_query($query);; 5.) You're missing an opening curly brace here: if (mysql_affected_rows() <= 0) 6.) You're missing a semicolon here: echo "We couldn't find the account to change in our records" ---------- Forwarded message ---------- From: <danbrown@php.net> Date: Fri, Aug 1, 2008 at 12:16 PM Subject: [PHP-NOTES] note 84843 deleted from function.mysql-affected-rows by danbrown To: php-notes@lists.php.net Note Submitter: george at torindul-designs dot co dot uk Reason: bad code ---- 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); ?> -- PHP Notes Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- </Daniel P. Brown> Better prices on dedicated servers: Intel 2.4GHz/60GB/512MB/2TB $49.99/mo. Intel 3.06GHz/80GB/1GB/2TB $59.99/mo. Dedicated servers, VPS, and hosting from $2.50/mo.

« previous php.notes (#143014) next »