Jasper99 Posted February 15, 2009 Share Posted February 15, 2009 Hello, in the following script I have a table (mysql) and a textfield to edit the data of the table (all in one page). Before it was separated (edit.php). Now my problem is that the textfield shows all the time only the last value of the table. I can edit it but I can't choose another value. I think the reason could be, that the script chooses a value over the radio button and in the same time it should edit it. Could it be a problem that radio butten and hidden field have the same name? What can I do? (Sorry that I posted the whole script.) <form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post"> . <?php if (isset($_POST['Start'])): $id = $_POST['id']; $Start = $_POST['Start']; $sql = "UPDATE Info SET Start='$Start' WHERE id='$id'"; if (mysql_query($sql)) { echo '<p>Details updated.</p>'; } else { exit('<p>Error updating details: ' . mysql_error() . '</p>'); } ?> <?php else: $id = $_GET['id']; $Start = $_GET['Start']; $house = @mysql_query("SELECT Start FROM Info WHERE id='$id'"); if (!$house) { exit('<p>Error fetching details: ' . mysql_error() . '</p>'); } $house = mysql_fetch_array($house); $Start = $house['Start']; $Start = htmlspecialchars($Start); ?> <table border = "1"> <colgroup> <col width="20" /> <col width="187" /> </colgroup> <tr><th></th><th>Start</th></tr> <?php $houses = @mysql_query( 'SELECT * FROM Info'); if (!$houses) { echo '</table>'; exit('<p>Error retrieving from database!<br />'. 'Error: ' . mysql_error() . '</p>'); } while ($house = mysql_fetch_array($houses)) { $id = $house['id']; $Start = htmlspecialchars($house['Start']); [color=red]echo "<tr><td><input type=\"radio\" name=\"id\" value=\"".$id."\" > [/color] </td>"; echo "<td>$Start</td>"; echo "</tr>\n"; } ?> </table> <textarea name="Start" rows="2" cols="25"> <?php echo $Start; ?> </textarea> [color=red]<input type="hidden" name="id" value="<?php echo $id; ?>" />[/color] <input type="submit" value="SUBMIT" /> </form> <?php endif; ?> Thank you. Quote Link to comment Share on other sites More sharing options...
btherl Posted February 16, 2009 Share Posted February 16, 2009 Yes, having the same name could be a problem. Try giving them different names. Quote Link to comment 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.