Jump to content

Foreach help


fubowl

Recommended Posts

 

    public function update($data, $table, $where) {

        foreach ($data as $column => $value) {

            $sql = "UPDATE $table SET $column = $value WHERE $where";

print "table: ".$table." column: ".$column." where: ".$where;

            mysql_query($sql) or die(mysql_error());

        }

        return true;

    }

 

 

$data:

$data = array(

    "username" => "Jack",

    "email" => "[email protected]"

);

 

 

$db->update($data, "users", 'id=1');

 

Working on this code that updates a column from a class. Everything is fine except for one issue.

 

As of right now $column is set to "Jack" which outputs an error, instead of what it should be as "username". I'm sure it's something really simple, so any assistance is appreciated. Any ideas? Problem area is listed in red.

Link to comment
https://forums.phpfreaks.com/topic/216060-foreach-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.