I am trying to post a form to the database. The form is to add a news story to the news page. I have add news and edit new. Edit news is working fine and posting to the database, but adding news is not working.
[code=php]<?php
include(“config.php”);
if(isset($_POST[‘submit’]))
{//begin of if($submit).
// Set global variables to easier names
// and pervent sql injection and apostrophe to break the db.
$title = mysql_escape_string($_POST[‘title’]);
$text1 = mysql_escape_string($_POST[‘text1’]);
$text2 = mysql_escape_string($_POST[‘text2’]);
$text3 = mysql_escape_string($_POST[‘text3’]);
$text4 = mysql_escape_string($_POST[‘text4’]);
$text5 = mysql_escape_string($_POST[‘text5’]);
$text6 = mysql_escape_string($_POST[‘text6’]);
//check if (title) field is empty then print error message.
if(!$title){ //this means If the title is really empty.
echo “Error: News title is a required field. Please fill it.”;
exit(); //exit the script and don’t do anything else.
}// end of if
//run the query which adds the data gathered from the form into the database
$result = mysql_query(“INSERT INTO news (title, dtime, text1, text2, text3, text4, text5, text5)
VALUES (‘$title’,NOW(),’$text1′,’$text2′,’$text3′,’$text4′,’$text5′,’$text6′)”,$connect);
//print success message.
echo “<b>Thank you! News added Successfully!<br><br></b><span class=’class6′><a href=’../members_home.php’>Members Area</a></style> | <span class=’class6′><a href=’../index.php’>Home</a></style>”;
}//end of if($submit).
// If the form has not been submitted, display it!
else
{//begin of else
?>
After i post the form, i get the successful message so its not a connection problem, but it is not adding to the databse :S
Cheers,
Dan