BelowZero Posted March 2, 2012 Share Posted March 2, 2012 When I display the data in my database I have included a radio button in each row. When the button is clicked, the intention is to delete all the information in that row. But it won't delete anything... Here's the form: <FORM Method = "POST" action ="update_tee_times.php"> <?php include("opendatabase.php"); $dateID = $_POST[teetimedate]; $result = mysql_query(" SELECT Date, Player1,Player2,Player3,Player4,Player5,Time, IF( TIME(Time) BETWEEN '17:30:00' AND '19:30:00','FFFF66','FFFFFF') AS color FROM Daysheets WHERE Date ='$dateID'"); echo "<h1>"; echo date("l, F d, Y", strtotime($dateID)); echo "</h1>"; echo "<table align=center width=700 border=1>\n"; echo "<th>Clear</th><th>Time</th><th>Player 1</th><th>Player 2</th><th>Player 3</th><th>Player 4</th><th>Player 5</th> <th>M</th><th>W</th><th>G</th>"; $i=0; while($row = mysql_fetch_array( $result )) { $dateID = $row['Date']; $timeID = $row['Time']; echo "<tr>"; echo "<td>"; echo "<input type='radio' name='time1[$i]' value='$timeID'>"; //HERE'S THE RADIO BUTTON echo "</td><td>"; echo date("g:i ", strtotime($row[Time])); echo "</td><td>"; echo "<input type='text' size='17' value= '$row[Player1]' name='player1[$i]' style ='background-color:#{$row['color']};'>"; echo "</td><td>"; echo "<input type='text' size='17' value= '$row[Player2]' name='player2[$i]' style ='background-color:#{$row['color']};'>"; echo "</td><td>"; echo "<input type='text' size='17' value= '$row[Player3]' name='player3[$i]' style ='background-color:#{$row['color']};'>"; echo "</td><td>"; echo "<input type='text' size='17' value= '$row[Player4]' name='player4[$i]' style ='background-color:#{$row['color']};'>"; echo "</td><td>"; echo "<input type='text' size='17' value= '$row[Player5]' name='player5[$i]' style ='background-color:#{$row['color']};'>"; echo "</td><td>"; echo "<input type='text' size='2' value= '$row[Men]' name='women' style ='background-color:#{$row['color']};'>"; echo "</td><td>"; echo "<input type='text' size='2' value= '$row[Women]' name='women' style ='background-color:#{$row['color']};'>"; echo "</td><td>"; echo "<input type='text' size='2' value= '$row[Guest]' name='guests' style ='background-color:#{$row['color']};'>"; echo "<input type='hidden' name='date[$i]' value='$dateID'>"; echo "<input type='hidden' name='time2[$i]' value='$timeID'>"; echo "</td></tr>"; $i++; } echo "</table>"; mysql_close($con); ?> <br /><br /> <input type="Submit" name="Submit" value="Update Tee Times"> </FORM> And here's the form action: <?php header("Location: /teetimes/preteetimesadmin.php"); include("opendatabase.php"); $size = count($_POST['player1']); $timeID1 = $_POST['time1'][$i]; //HERE'S WHERE I'M TRYING TO DELETE THE DATA. mysql_query(" UPDATE Daysheets SET Player1='', Player2='', Player3='', Player4='', Player5='' WHERE Time ='$timeID1' "); //HERE'S THE UPDATE, WHICH WORKS FINE. $i=0; while ($i < $size) { $dateID = $_POST['date'][$i]; $timeID2 = $_POST['time2'][$i]; $player1 = ($_POST['player1'][$i]); $player2 = ($_POST['player2'][$i]); $player3 = ($_POST['player3'][$i]); $player4 = ($_POST['player4'][$i]); $player5 = ($_POST['player5'][$i]); mysql_query(" UPDATE Daysheets SET Player1='$player1', Player2='$player2', Player3='$player3', Player4='$player4', Player5='$player5' WHERE Date ='$dateID' AND Time ='$timeID2' "); $i++; } mysql_close($con) ?> When I add or update any information it works fine. It just won't delete anything where the radio button is clicked. Any help appreciated! Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/258134-using-radio-button-to-update-database/ Share on other sites More sharing options...
Proletarian Posted March 2, 2012 Share Posted March 2, 2012 Echo a mysql_error() after your mysql_query(update) statement. Need more details on why "it's not working." Quote Link to comment https://forums.phpfreaks.com/topic/258134-using-radio-button-to-update-database/#findComment-1323221 Share on other sites More sharing options...
mikosiko Posted March 2, 2012 Share Posted March 2, 2012 It just won't delete anything well.. among other issues there is not DELETE in the posted code Quote Link to comment https://forums.phpfreaks.com/topic/258134-using-radio-button-to-update-database/#findComment-1323224 Share on other sites More sharing options...
Proletarian Posted March 2, 2012 Share Posted March 2, 2012 It just won't delete anything well.. among other issues there is not DELETE in the posted code It looks like he's just overwriting it with blanks, which is kind of like deleting it, just not the actual row; maybe he's not wanting to row, just remove the data in the row. But, I dunno. OP needs to explain intention. Quote Link to comment https://forums.phpfreaks.com/topic/258134-using-radio-button-to-update-database/#findComment-1323226 Share on other sites More sharing options...
batwimp Posted March 2, 2012 Share Posted March 2, 2012 Have you tried echoing out $timeID1 right after you set it to see if it contains valid data? Quote Link to comment https://forums.phpfreaks.com/topic/258134-using-radio-button-to-update-database/#findComment-1323229 Share on other sites More sharing options...
BelowZero Posted March 2, 2012 Author Share Posted March 2, 2012 Thanks for your responses. There are no errors reported. I don't need to "delete" the data. Just trying to write over it with blank spaces. batwimp, there is the problem. $timeID1 is NOT returning a value. But I also have a $timeID2 which IS returning a value. I've stared at the code trying to find a coding error but it all looks good to me. My eyes must be getting bleary... Any other ideas? Quote Link to comment https://forums.phpfreaks.com/topic/258134-using-radio-button-to-update-database/#findComment-1323268 Share on other sites More sharing options...
batwimp Posted March 2, 2012 Share Posted March 2, 2012 The very fist thing at the top of your action page is: header("Location: /teetimes/preteetimesadmin.php"); This will immediately redirect to that page, and none of the rest of the code will be run. Is that code actually running? Quote Link to comment https://forums.phpfreaks.com/topic/258134-using-radio-button-to-update-database/#findComment-1323273 Share on other sites More sharing options...
BelowZero Posted March 2, 2012 Author Share Posted March 2, 2012 Yes, it's running and works fine. All additions and changes I make are written to the database correctly (except when the radio button is clicked), then I'm redirected. Quote Link to comment https://forums.phpfreaks.com/topic/258134-using-radio-button-to-update-database/#findComment-1323292 Share on other sites More sharing options...
BelowZero Posted March 2, 2012 Author Share Posted March 2, 2012 Figured it out... I had to put $timeID1 inside the while statement to get a value. Then I just used an IF empty statement to test whether the row should be updated or written over. Works fine now. Thanks for your replies! Quote Link to comment https://forums.phpfreaks.com/topic/258134-using-radio-button-to-update-database/#findComment-1323319 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.