Page 1 of 1

foreach again

Posted: Thu Apr 27, 2006 8:29 pm
by a94060
I have this snippet of code in my script and when i run the script. it says :"Parse error: parse error, unexpected T_VARIABLE, expecting '(' in /var/www/signup/index.php on line 27" and im pretty sure that i do not need a "(" in there.

Code: Select all

query = "INSERT INTO ftpuser ('userid','passwd','uid','gid','homedir','shell') VALUES ('$uname', '$pass' , '5500' , '5500' ,'/ftp' , 					'/sbin/nologin')";
	$query2 = "INSERT INTO myip ('uname', 'name', 'ip') VALUES ('$uname' ,'$name' ,'$ip')";
	//make it run recursivly

	$queries = array ("q1" => "$query" ,
				  "q2" => "$query2" );
		foreach $queries as $do {
			mysql_query($do);
			}

Posted: Thu Apr 27, 2006 8:49 pm
by dbevfat
see http://www.php.net/foreach for the syntax of foreach.

Re: foreach again

Posted: Fri Apr 28, 2006 5:09 am
by a94060
a94060 wrote:I have this snippet of code in my script and when i run the script. it says :"Parse error: parse error, unexpected T_VARIABLE, expecting '(' in /var/www/signup/index.php on line 27" and im pretty sure that i do not need a "(" in there.

Code: Select all

query = "INSERT INTO ftpuser ('userid','passwd','uid','gid','homedir','shell') VALUES ('$uname', '$pass' , '5500' , '5500' ,'/ftp' , 					'/sbin/nologin')";
	$query2 = "INSERT INTO myip ('uname', 'name', 'ip') VALUES ('$uname' ,'$name' ,'$ip')";
	//make it run recursivly

	$queries = array ("q1" => "$query" ,
				  "q2" => "$query2" );
		foreach $queries as $do {
			mysql_query($do);
			}

i think i got it. it wants me to write

Code: Select all

$queries = array ("q1" => "$query" ,
				  "q2" => "$query2" );
		foreach ($queries as $do) {
			mysql_query($do);
			}

Posted: Fri Apr 28, 2006 5:11 am
by dbevfat
yes, it does :)

Posted: Fri Apr 28, 2006 10:21 am
by a94060
ok thanks, i will make sure i refer to the manual more often. I dont know but for osdme reason i dont seem to understand what i am doing some times.

Posted: Fri Apr 28, 2006 10:49 am
by dbevfat
It's like that with all of us sometimes, I guess. The understanding grows with experience and amount of code. :)