Jump to content

[SOLVED] Accessing The Post Array


Bendude14

Recommended Posts

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

 

 

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.