foreach again

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

foreach again

Post 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);
			}
User avatar
dbevfat
Forum Contributor
Posts: 126
Joined: Tue Jun 28, 2005 2:47 pm
Location: Ljubljana, Slovenia

Post by dbevfat »

see http://www.php.net/foreach for the syntax of foreach.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Re: foreach again

Post 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);
			}
User avatar
dbevfat
Forum Contributor
Posts: 126
Joined: Tue Jun 28, 2005 2:47 pm
Location: Ljubljana, Slovenia

Post by dbevfat »

yes, it does :)
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post 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.
User avatar
dbevfat
Forum Contributor
Posts: 126
Joined: Tue Jun 28, 2005 2:47 pm
Location: Ljubljana, Slovenia

Post by dbevfat »

It's like that with all of us sometimes, I guess. The understanding grows with experience and amount of code. :)
Post Reply