Jump to content

Problems with textfield for edit


Jasper99

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/145347-problems-with-textfield-for-edit/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.