Re: function problem

From: Date: Mon, 03 Jan 2005 06:38:17 +0000
Subject: Re: function problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-205492@lists.php.net to get a copy of this message
Hi Viktor, Viktor Popov wrote:
Hi, I'm trying to do the following but I don't have any success. Could you help me here... I have this code in mu page: <?php include "script/functions.php"; require 'script/common.inc'; $valid = TRUE; if (isset ($_POST['submit'])) {
    foreach($_POST as $key=>$value) {
      $$key = $value;
    }
This is a huge security hole, far better is to do this: if (isset ($_POST['submit'])) {
    foreach (array('field1', 'field2', 'field3') as $allowedfield) {
        if (isset($_POST[$allowedfield])) {
            $$allowedfield = $_POST[$allowedfield];
        }
    }
} In addition, you really need to use mysql_escape_string() to avoid serious potential problems with sql injection attacks. [NOTE: mysql_db_query() is deprecated, use mysql_query()/mysql_select_db()] mysql_select_db($DB); mysql_query('INSERT INTO blahbalhblahblah VALUES("' . mysql_escape_string($field1) . '" ....'); Regards, Greg

« previous php.general (#205492) next »