How to get MySQL database to appear on index.php
- by Teddy Truong
Hi, I have a submission form on my website (index.php) and I have the data(user submissions) being stored into a MySQL database. Right now, I have the user submitting a post and then the page directs them to an update.php which shows what they inputed.
However, I want all of the data in the database in MySQL to be shown on the index.php. It's a lot like a comment system. User submits a post... and sees their post above the other submitted posts all on the same page. I think I'm missing AJAX... ?
Here is the code for index.php
<div align="center">
<p> </p>
<h2 align="center" class="Title"><em><strong>REDACTED</strong></em></h2>
<form id="form1" name="form1" method="post" action="update.php">
<hr />
<label><br />
<form action="update.php" method="post">
REDACTED: <input type="text" name="text" />
<input type="submit" />
</form>
</label>
</form>
</div>
On update.php I have this:
?php
$text = $_POST['text'];
$myString = "REDACTED";
mysql_connect ("db----.net", "-----3", "------------") or die ('Error: ' . mysql_error());
mysql_select_db ("-----------");
$query="INSERT INTO TextArea (ID, text) VALUES ('NULL', '".$text."')";
mysql_query($query) or die ('Error updating database');
echo " $myString "," $text ";
?>
Thanks a lot!