I’ve been having some trouble with a basic news posting page, where it’s entering the blank fields into the database before their filled out and the submit is clicked and was hoping someone out there can spot where I’ve mucked up by missing or not adding something in there, I have a page set for displaying the news and was entering it manually, which was a pain, so I’m now a little stuck on where to go, because I can still enter info into the fields and submit and it does that fine, but it’s the pre-submit that’s got me stumped.
newsadd.htm (template file)
[code]
Author | : | |
News Title | : | |
News Text | : | Enter text here... |
newsadd.php
[php]//include database information
include(“theme/news/config.php”);
//connect.
$mysql[‘connection’] = mysql_connect($databaseinfo[‘host’], $databaseinfo[‘user’], $databaseinfo[‘password’]);
//select mysql database
$mysql[‘db’] = mysql_select_db($databaseinfo[‘dbname’],$mysql[‘connection’]);
include("/theme/header.htm");
include("/theme/newsadd.htm");
include("/theme/footer.htm");
// Get values from form
$articleauthor=$_POST[‘article_author’];
$articletitle=$_POST[‘article_title’];
$articletext=$_POST[‘article_text’];
// Insert data into mysql
$sql = “INSERT INTO phpns_articles (article_author, article_title, article_text)VALUES(’$articleauthor’, ‘$articletitle’, ‘$articletext’)”;
$result = mysql_query($sql);
// if successfully insert data into database, displays message “Successful”.
if($result){
echo “Successful”;
echo “
”;
echo “Back to main page”;
}
else {
echo “ERROR”;
}
// close connection
mysql_close();
?>[/php]
config.php (for the sake of possibly needing it, subbed in XxxxxX)
[php]<?php
//The Host is where the mySQL database is stored. Usually localhost.
$databaseinfo[‘host’] = “localhost”;
//The user your database is assigned to.
$databaseinfo[‘user’] = “root”;
//The password of your user.
$databaseinfo[‘password’] = “XxxxxX”;
//The database name that phpns will use.
$databaseinfo[‘dbname’] = “XxxxxX”;
//The table prefix defined on the database.
$databaseinfo[‘prefix’] = “XxxxxX”;
?>[/php]