data after 'update' visible in table

Discussion in 'PHP' started by Pocoyo, Feb 11, 2009.

  1. #1
    Hello,

    with the script above I want to add new data in a table (mysql).
    But before I can see the data in the table I have to update the page.


    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
    ..
    <input type="submit" value="HINZUFÜGEN"  />
    <input type="submit" value="SUBMIT" />
    HTML:
    <?php		
      if (isset($_POST['Anfang'])):   
      $Anfang = $_POST['Anfang'];  
      $Titel = $_POST['Titel'];    
    
      $sql = "INSERT INTO Info SET
          Anfang='$Anfang',      
          Titel='$Titel',       
          
      if (@mysql_query($sql)) {
        echo '<p>New info</p>';
      } else {
        exit('<p>Error adding new info: ' . mysql_error() . '</p>');
      }
    
    else:  
    ?>
    PHP:
    <table>
    <tr>
    <td>
    <input name="Anfang" type="text" />
    </td>
    <td>
    <textarea name="Titel" rows="2">
    </textarea>
    </td>
    </tr>
    </table>
    HTML:
    <?php endif; ?>
    PHP:
    ..
    </form>
    HTML:
    How do I have to change the script, so that with 'submit' I can see the new data in the table?
     
    Pocoyo, Feb 11, 2009 IP
  2. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #2
    reaplce
    echo '<p>New info</p>';
    with
    echo '<p>$_POST[Anfang] $_POST[Titel]</p>';
     
    crivion, Feb 11, 2009 IP
  3. Pocoyo

    Pocoyo Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you for you help but it doesn't work.

    For the data output in the table I have the following:

    <table border = "1">

    <colgroup>
    <col width="20" />
    <col width="187" />
    <col width="187" />
    </colgroup>

    <tr><th></th><th>Anfang</th><th>Title</th></tr>

    <?php

    $select = 'SELECT *';
    $from = 'FROM Info';
    $houses = @mysql_query( $select . $from . $where . $orderby );
    if (!$houses) {
    echo '</table>';
    exit('<p>Error retrieving jokes from database!<br />'.
    'Error: ' . mysql_error() . '</p>');
    }

    while ($house = mysql_fetch_array($houses)) {
    $id = $house['id'];
    $Anfang = htmlspecialchars($house['Anfang']);
    $Titel = htmlspecialchars($house['Titel']);

    echo "<td>$Anfang</td>";
    echo "<td>$Titel</td>";
    echo "</tr>\n";
    }
    ?>
    </table>

    I still have to update the page after I added date to see it in the table.
     
    Pocoyo, Feb 12, 2009 IP
  4. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #4
    
    <table border = "1">
    
    <colgroup>
    <col width="20" />
    <col width="187" />
    <col width="187" />
    </colgroup>
    
    <tr><th></th><th>Anfang</th><th>Title</th></tr>
    
    <?php
    
    $houses = @mysql_query("select * from info");
    if (!$houses) {
    echo '</table>';
    exit('<p>Error retrieving jokes from database!<br />'.
    'Error: ' . mysql_error() . '</p>');
    }
    
    while ($house = mysql_fetch_array($houses)) {
    $id = $house['id'];
    $Anfang = htmlspecialchars($house['Anfang']);
    $Titel = htmlspecialchars($house['Titel']);
    
    echo "<td>$Anfang</td>";
    echo "<td>$Titel</td>";
    echo "</tr>\n";
    }
    ?>
    </table>
    
    PHP:
     
    crivion, Feb 13, 2009 IP