Hi

I would like to be able to use a foreach loop to make variables directly from the result row like this

        $_SESSION['client'] = array();
	$sql = "SELECT * FROM client WHERE ID_Client_SITE='".$id."'";
	$res = mysql_query($sql)or die(mysql_error());
	if (!$res) {
		$_SESSION['client']["error"] = "not found";
	}else{
		$_SESSION['client']["error"] = "";
		$row = mysql_fetch_row($res){	
		foreach ($row as $k => stripslashes($v)) {
   		$_SESSION['client'][$k] => $v;
		}	
	}
//
//

the problem is that i'm getting parse error from the line

$row = mysql_fetch_row($res){

but i just can't see why

also, i want to use the db table column name as the key name in the session variable (eg the $row['id'] will give $_SESSION['client']["id"] ) but i have a feeling that using mysql_fetch_row() is not going to let me do that because it seems that it just returns an arrray without key names

so what would be the best way overall to go about what i'm trying to do ?

thanks

    also, i want to use the db table column name as the key name in the session variable (eg the $row['id'] will give $_SESSION['client']["id"] ) but i have a feeling that using mysql_fetch_row() is not going to let me do that because it seems that it just returns an arrray without key names

    so what would be the best way overall to go about what i'm trying to do ?

    You can replace:

            $row = mysql_fetch_row($res){    
    foreach ($row as $k => stripslashes($v)) { $_SESSION['client'][$k] => $v; }

    with:

    $_SESSION['client'] = mysql_fetch_assoc($res);

      you're right on the button, as usual !

      i had to add in a

      		foreach ($_SESSION['client'] as $k => $v) {
         		$_SESSION['client'][$k] = stripslashes($v);
      		}

      but it all works perfectly now

      many thanks 🙂

        Do not do that (as in use stripslashes() ). Instead, set magic_quotes_gpc to off in php.ini.

          ok - i'll have a look but i'm not sure i'll be able to because the site is on shared hosting - maybe i can override the php.ini setting

          thanks again

            ok - i'll have a look but i'm not sure i'll be able to because the site is on shared hosting - maybe i can override the php.ini setting

            If your host allows you to override php.ini settings with a .htaccess file, you can do that. ini_set() will not work as by the time it is executed, the incoming data have already been (possibly incorrectly) escaped.

              Write a Reply...