My code is supposed to present the user with a form and when they hit submit, send the entered data as well as the current users username to the database table.
Then, eventually I will pull the data from the database table and present it on the page.
(It is a simple bulletin board.)
I am using Joomla 3.2.2 and Sorcerer to add my php code.
I can’t seem to get the simplest lines of code to do anything at all. I have tried countless possibilities from all over the internet and from 3 “Learn PHP” books that I have.
From all of my research, inserting data into the database is one of the most basic things of all yet, I can not make it happen for some reason and it is very frustrating.
The PHP code I have is below. This appears to work from the website view…but nothing gets added to my database table.
[php]
<?php $message = $_POST['postArea']; if(isset($_POST['submit'])){ mysql_query("INSERT INTO 'bulletin_board' VALUES('$message')"); Print "Added to Database"; } ?>[/php]
Here is the code with the HTML form:
<body>
<?php
$message = $_POST['postArea'];
if(isset($_POST['submit'])){
mysql_query("INSERT INTO 'bulletin_board' VALUES('$message')");
Print "Added to Database";
}
?>
<!--FORM POST-->
<form name="formPost" method="POST">
<fieldset>
<input name="postArea" type="text" maxlength="200" />
</fieldset>
<fieldset class = "buttonPost">
<input type = "hidden" name = "action" value = "insert" />
<p><input type = "submit" name="submit" value="Post"></p>
</fieldset>
</form>
</body>