Bendude14 Posted July 31, 2008 Share Posted July 31, 2008 I have a list of about 70 players and next to each name there is a checkbox. Each checkboxes name is equivalent to the players name. When the checkboxes are selected and then submitted i need to collect this information. Obviously i dont want to do it indiviually like so $player1 = $_POST['player name']; so i am trying to access the POST array like this <?php foreach($_POST as $name => $player) { if($name != "week" || "update") { $sql = "INSERT INTO results_players (player_name, week) VALUES ('$name', '$player[week]')"; $result = mysql_query($sql) or trigger_error('Query failed: '. mysql_error()); } }//end of loop ?> But this still enters the values week and update into my database when i only want the names inserting. I also want the value of week to be inserted for every player in the week column but its only inserts it in the week column where its inserted week into player_name I hope this makes sense Thanks Quote Link to comment Share on other sites More sharing options...
thebadbad Posted July 31, 2008 Share Posted July 31, 2008 Your syntax in the if statement is wrong. You say: If $name != "week" is true, OR "update" is true (which it always is), then do this. You're looking for if($name != "week" && $name != "update") { I don't get your second problem - where does $player[week] come from? $player can't be an array when coming from a POST value (only if an array is inserted into the POST array afterwards). Quote Link to comment Share on other sites More sharing options...
Bendude14 Posted July 31, 2008 Author Share Posted July 31, 2008 Ok thanks for that, fixed the first problem. Well i am trying to enter the week number into the database for each player that is submitted but when i just use $sql = "INSERT INTO results_players (player_name, week) VALUES ('$name', '$week')"; i get this error? Notice: Undefined variable: week in C:\wamp\www\mqserver\up\update_players.php on line 16 where does $player[week] come from? $player can't be an array when coming from a POST value (only if an array is inserted into the POST array afterwards). Yes i see what you mean, was just trying everything to get it work Quote Link to comment Share on other sites More sharing options...
Bendude14 Posted July 31, 2008 Author Share Posted July 31, 2008 Ok i just added this before the foreach loop and everything works $week = $_POST['week']; Thanks for the help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.