Converting from Output to Input !

Discussion in 'PHP' started by ausgezeichnete, Dec 22, 2007.

  1. #1
    i want to edit a table but in the same page
    when i click on Edit,the output value converts to input to be able to edit it
    but i dont know why it didnt work????????
    do u think it needs Ajax???
    this is my code

    
    <table border="1" align="center">
      <tr>
        <th>Name</th>
      </tr>
      <?php do { ?>
        <tr>
    	<?php if(!isset($_POST['Submit'])){?>
          <td><?php echo $row_Recordset1['porto_name']; ?></td>
    	  <?php }else{?>
    	  <td><input type=text value=<?php echo $row_Recordset1['porto_name']; ?> /></td>
    	  <?php }?>
    	  <td><input name="Submit" type="submit" value="edit"></td>
    	  
    	  
    	  <td><a href="portofolio_delete.php?porto_ID=<?php echo $row_Recordset1['porto_ID']; ?>">Delete</a></td>
    	  
        </tr>
        <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
    </table>
    
    PHP:

     
    ausgezeichnete, Dec 22, 2007 IP
  2. tonybogs

    tonybogs Peon

    Messages:
    462
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try changing your code to something like this.

    
    <table border="1" align="center">
      <tr>
        <th>Name</th>
      </tr>
      <?php do { ?>
        <tr>
        <form action="THE SAME FILENAME" method="post" />
        <?php if(!isset($_POST['action'])){?>
          <td><?php echo $row_Recordset1['porto_name']; ?></td>
          <?php }else{?>
          <td><input type=text value=<?php echo $row_Recordset1['porto_name']; ?> /></td>
          <?php }?>
          <td>
          <input type="hidden" name="action" value="edit" />
          <input name="Submit" type="submit"></td>
          </form>
          
          <td><a href="portofolio_delete.php?porto_ID=<?php echo $row_Recordset1['porto_ID']; ?>">Delete</a></td>
          
        </tr>
        <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
    </table>
    
    PHP:
    The problem is that you arent actually submitting the form. Also, you need the hidden value because not all browsers pass the value of the button.

    You can also use Javascript to do this, but it'll involve more rewritting than just a few lines :)

    Good Luck
     
    tonybogs, Dec 22, 2007 IP