John Black wrote:
> PHP 101: PHP For the Absolute Beginner
> http://devzone.zend.com/node/view/id/627

I guess I should have looked at the examples before recommending them. 
DO NOT FOLLOW THE DATABASE EXAMPLES on the website above.

They try to teach stupid stuff like this below:
// create query
$query = "SELECT * FROM users WHERE name = '" . $_POST['name'] . "' AND 
pass = SHA1('" . $_POST['pass'] . "')";

Using any kind of user input in a databases without escaping and/or 
doing input validation is stupid, I am sad to see this on Zend.com of 
all people, they should know better.
Why is this stupid, because if a user enters the name User'Name
it will break the query.

At a different point in your script this may lead to your database 
listing information you don't want to...
Example:
"SELECT * FROM tbl_customers WHERE ID = \"{$_POST['customer_id']}\" ";
And the bad user enters the following string into a search box
           1" OR "1=1

The query will turn into:
SELECT * FROM tbl_customers WHERE ID = "1" OR "1=1"

Which may show ALL customers in the tbl_customers if you use dynamic 
handling of the SQL return....

At least escape properly, in this case for mysql
$cust_id = mysql_real_escape_string($_POST['customer_id']);
"SELECT * FROM tbl_customers WHERE ID = \"$cust_id\" ";

Which will now end up as:
SELECT * FROM workorder_customers WHERE ID = "1\" OR \"1=1"


Reply via email to