Search code examples
phpeditform-fields

How to edit data from form field?


when i edit data from form field it only select/fetch one word though form field has many words/ or complete sentence where is wrong?

 <?php
 //getting id from url
 $id = $_GET['id'];

 //selecting data associated with this particular id
 $result = mysql_query("SELECT * FROM list WHERE id=$id");

  while($res = mysql_fetch_array($result))
 {
  $Test_name = $res['Test_name'];

  }
  ?>

 <form name="form1" method="post" action="edit.php">
    <table border="0">


        <tr> 
            <td>Test Name</td>
            <td><input type="text" name="Test_name" value=<?php echo 
             $Test_name;?>></td>
        </tr>

        <tr>
            <td><input type="hidden" name="id" value=<?php echo 
             $_GET['id'];?>></td>
            <td><input type="submit" name="update" value="Update"></td>
        </tr

    </table>
    </form>

Solution

  • You can use TextArea for long value edit. Hope below example will help you.

    <form name="form1" method="post" action="edit.php">
        <table border="0">
    
    
            <tr> 
                <td>Test Name</td>
                <td><textarea name="Test_name" value=<?php echo 
                 $Test_name;?>><?php echo 
                 $Test_name;?></textarea></td>
            </tr>
    
            <tr>
                <td><input type="hidden" name="id" value=<?php echo 
                 $_GET['id'];?>></td>
                <td><input type="submit" name="update" value="Update"></td>
            </tr
    
        </table>
    </form>