Jump to content

[SOLVED] Problems updating fields in DB with current code -- please help


lunac

Recommended Posts

Ok,

I have an application with a section to manage users. For some reason my routine for updating level permissions is not working. Can anyone figure out what I did wrong?

 

Here's the code:

$x = mysqlSelect($_tables['modules']);
	while($y = @mysql_fetch_assoc($x)){
			$mods[] = $y;
	}
	foreach ($mods as $modu){
		//check if module value exist otherwise add it
		$check = usr($modu['level'], $_POST['id']);
		if($check != ''){
		lib_executeQuery("UPDATE " . $_tables['usersmeta'] . " set meta_value='" . $_POST[$modu['level']] ."' WHERE user_id='" . $_POST['id'] . "' AND meta_key='" . $modu['level'] . "'");
		} else {
			$post['user_id'] = $_POST['id'];
			$post['meta_key'] = $modu['level'];
			$post['meta_value'] = $_POST[$modu['level']];
			mysqlInsert($post,$_tables['usersmeta']);
		}

 

Here are the supporting functions:

function mysqlInsert($array,$table){
        unset($array['Submit']);

        $keys   = array_keys ($array);
        $values = array_values ($array);

        $kquery = join("','",$keys);
        $kquery = str_replace("'","",$kquery);

        $vquery = join("','",$values);

        $query  = "insert into $table (" . $kquery . ") values ('" . $vquery . "')";
        lib_executeQuery($query) or die(mysql_error());
}

function lib_executeQuery($query,$dbLink=""){
        // Execute an SQL query passed to this function
        if($dbLink){
        	$link = $dbLink;
        } else {
        	$link = lib_databaseConnect();
        }
        $dbResult = mysql_query($query, $link)
            or die ("Database Class: MySQL Error: " . mysql_error() );
        return $dbResult;
    }

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.