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?
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.
<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: