PHP - Calling function inside another class -> function

Posted by Kolind on Stack Overflow See other posts from Stack Overflow or by Kolind
Published on 2011-11-18T17:09:37Z Indexed on 2011/11/18 17:51 UTC
Read the original article Hit count: 137

Filed under:

I'm trying to do this:

class database {    
function editProvider($post)
{   
    $sql = "UPDATE tbl SET ";
        foreach($post as $key => $val):
            if($key != "providerId")
            {
                $val = formValidate($val);
                $sqlE[] = "`$key`='$val'"; 
            }
        endforeach;

    $sqlE = implode(",", $sqlE);

    $where = ' WHERE `id` = \''.$post['id'].'\'';
    $sql = $sql . $sqlE . $where;

    $query = mysql_query($sql);

    if($query){
        return true;
    }
}
//
}//end class

And then use this function * INSIDE of another class *:

function formValidate($string){
  $string = trim($string);
  $string = mysql_real_escape_string($string);
  return $string;
}
//

.. on $val. Why doesn't this work? if I write in a field of the form, it's not escaping anything at all. How can that be?

* UPDATE * handler.php:

if(isset($_GET['do'])){

if($_GET['do'] == "addLogin")
{
    $addLogin = $db->addLogin($_POST);
}

if($_GET['do'] == "addProvider")
{
    $addProvider = $db->addProvider($_POST);
}

if($_GET['do'] == "editProfile")
{
    $editProfile = $db->editProfile($_POST);
}

if($_GET['do'] == "editProvider")
{
    $editProvider = $db->editProvider($_POST);
}
}
//end if isset get do

** The editProvider function works fine except for this :-) **

© Stack Overflow or respective owner

Related posts about php