Jump to content

Using radio button to update database


BelowZero

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

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.