galvin Posted November 30, 2008 Share Posted November 30, 2008 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 https://forums.phpfreaks.com/topic/134828-solved-update-info-in-table-from-a-simple-form/ Share on other sites More sharing options...
xtopolis Posted December 1, 2008 Share Posted December 1, 2008 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 https://forums.phpfreaks.com/topic/134828-solved-update-info-in-table-from-a-simple-form/#findComment-702715 Share on other sites More sharing options...
galvin Posted December 29, 2008 Author Share Posted December 29, 2008 thanks! Link to comment https://forums.phpfreaks.com/topic/134828-solved-update-info-in-table-from-a-simple-form/#findComment-725372 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.