Hi there rs7272,
I have partly re-written this for you, added some security & better error handling. Typed on the fly but it should do the job ;) Commented where I needed to for clarity
<?php
//check to see if form isset & holds value
if(isset($_POST['submit']) && ($_POST['submit'] == "add")){
//assign vars & cleanse input (always sanitise user input)
$Headline = strip_tags($_POST['Headline']);
$formBody = strip_tags($_POST['Body']);//changed var name as it *might be a reserved word*
$Closing = strip_tags($_POST['Closing']);
//establish connection once working, remove the error handler just leave as .... "password"); etc ;)
$con = mysql_connect("localhost", "database", "password") or die(mysql_error());
//select db
mysql_select_db("database", $con);
//perform query & add vars into query
$sqlQuery = "INSERT INTO `PT_Articles` ( `Headline`, `Body`, `Closing`) VALUES ('".$Headline."', '".$formBody."', '".$Closing."') LIMIT 1";
//run query & if successful display message
if(mysql_query($sqlQuery)){
//echo success message here
echo "Successfully added into DB";
}else{
//Error occured in adding to DB
echo "error has occured";
}
//close connection
mysql_close($con);
//always good to handle a mis-set form submission
}else{
//redirect back to form as error has occurred
header("location: NAME_OF_THIS_FILE_HERE.php");
}
//lastly display original page, the insert should be successful IF it was actioned
?>
<html>
<head>
<title>Adding value to DB
</title>
</head>
<body>
<form method="post" action="addarticle.php">
<input type="text" name="Headline" /><br>
<textarea name="Body"></textarea><br>
<textarea name="Closing"></textarea><br>
<input type="submit" name="submit" value="add" />
</form>
</body>
</html>
Not sure whether you are fussed about being W3C compliant but, its worth putting double quotes around the attributes and their values, makes for better coding IMHO.
[EDIT]:
There may be no error messages, but do you have them turned on by default? if not just do this as the first line of code in the script:-
<?php
//error reporting level
error_reporting(E_ALL);//This flags up everything, remove this line when going live though :)
Hope it helps you,
Cheers,
MRb
[edited by: Matthew1980 at 8:12 pm (utc) on Jun 29, 2010]