Jump to content

Foreach array problem


-Karl-

Recommended Posts

		$explode1 = $_POST['addmembers'];
	$explodeadd = explode("\r\n", $explode1);
	    $url = $arr['url'];
		foreach($explodeadd as $key => $member){
			//You do nothing with key, its just the line number (0 being the first line)
			//Now this loops trough every username and $index should be it.
			$addthem = mysql_query("INSERT INTO `members` (username,clanurl) VALUES ('$member','$url'");
			$runit = mysql_query($addthem);
		}

 

There's my code, echoing both $url and $member works, but it just won't do the query and I can't figure out why.

Link to comment
https://forums.phpfreaks.com/topic/198950-foreach-array-problem/
Share on other sites

change the query to this..

$addthem = mysql_query("INSERT INTO `members` (username,clanurl) VALUES ('$member','$url'") or die(mysql_error());

You tried to run the query twice too.. that wouldn't of been healthy.

So that also includes removing

$runit = mysql_query($addthem);

Returns:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

 

Now I've got to figure out what the problem is =[

 

That is your problem.

Are $member and $url even defined?

EDIIT: $url is defined, though from what I see $member isn't.

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.