-Karl- Posted April 18, 2010 Share Posted April 18, 2010 $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 More sharing options...
TeddyKiller Posted April 18, 2010 Share Posted April 18, 2010 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); Link to comment https://forums.phpfreaks.com/topic/198950-foreach-array-problem/#findComment-1044304 Share on other sites More sharing options...
-Karl- Posted April 18, 2010 Author Share Posted April 18, 2010 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 =[ Link to comment https://forums.phpfreaks.com/topic/198950-foreach-array-problem/#findComment-1044306 Share on other sites More sharing options...
TeddyKiller Posted April 18, 2010 Share Posted April 18, 2010 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. Link to comment https://forums.phpfreaks.com/topic/198950-foreach-array-problem/#findComment-1044307 Share on other sites More sharing options...
-Karl- Posted April 18, 2010 Author Share Posted April 18, 2010 Change it to: $addthem = mysql_query("INSERT INTO `members` (username,clanurl) VALUES ('$member','$url')") or die(mysql_error()); Working fine now, after $url it was missing the final ) Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/198950-foreach-array-problem/#findComment-1044311 Share on other sites More sharing options...
TeddyKiller Posted April 18, 2010 Share Posted April 18, 2010 Ah of course! I didn't see that. Link to comment https://forums.phpfreaks.com/topic/198950-foreach-array-problem/#findComment-1044312 Share on other sites More sharing options...
-Karl- Posted April 18, 2010 Author Share Posted April 18, 2010 Neither did I, it just slipped straight through! Link to comment https://forums.phpfreaks.com/topic/198950-foreach-array-problem/#findComment-1044315 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.