Jump to content

[SOLVED] UPDATE info in table from a simple form???


galvin

Recommended Posts

I have a simple form...

 


<form action="updatewinners.php" method="post">
<table id="login">
<tr>
<td><input type="checkbox" name="winner" value="1" />Eagles</td>
</tr>
<tr>
<td><input type="checkbox" name="winner" value="2" />Cowboys</td>
</tr>
<tr>
<td><input type="checkbox" name="winner" value="3" />Giants</td>
</tr>
<tr>
<td><input type="checkbox" name="winner" value="4" />Redskins</td>
</tr>
<td><input type="submit" name="submit" value="Update Winners" class="submit" /></td>
    </tr>
    </table>
    </form>

 

 

....and on the updatewinners.php page (code below), I am trying to process the information submitted via the form such that for any teams that are checked (whether it's 1, 2, 3 or all 4 of them), it will check my "Picks" table in MySQL and if those teamids are in the table with a result of 'o', it will change the result to 'w'.

 

Here is the updatewinners.php code that I thought would work, but it's not working....

 


if (isset($_POST['submit']) && $_POST['submit'] == "Update Winners" ) { 
             
            /* Not sure I need an array here but my thinking was to put all the "values" from the form into an array */
            $allteams = array(1,2,3,4);

if (in_array($_POST['value'],$allteams)) {
		$query = "UPDATE picks
		SET result = 'w'
		WHERE teamid = '{$_POST["value"]}'
		AND result = 'o'";
		$updateWinners = mysql_query($query, $connection);

			if (!$updateWinners) {
			die("Database query failed: " . mysql_error());
			} else {
			$success = "The Winners were updated!";
			}

} else {
	$didnotwork = "No teams are in table with a result of 'o'";
}


} else {
$didnotwork = "Info was not submitted.  Try again.";
}

 

I'm obviously missing some step with correctly processing the $_POST['value'] info (I think), so if anyone could help me, I would be very grateful. 

Link to comment
Share on other sites

Your inputs need to be in array form for php to read them:

 

<input type="checkbox" name="winner[]" value="1" />Eagles

<input type="checkbox" name="winner[]" value="2" />Cowboys

 

Examples: http://www.tizag.com/phpT/examples/formex.php

 

Fix that.  Your $_POST['winners'] array will now hold null or values 1-4.  Check back after you've got it to read the form values correctly, if you still have trouble.

Link to comment
Share on other sites

  • 4 weeks later...
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.