Let me explain what I have mentioned in my previous post.
This would be next stage of creating your project little bit in order.
This is also a basic concept but you should get an idea:
I will add 3 more files: functions.php, config.php, common.php
For now it's very bacis, it only holds database settings, but later you can add some global settings you need everywhere.
As you can see, common will include config and functions, start session and connect to database. Some people are against persistant connections to database, but I have never had problems with them in my life.
//connect to the base
if(!($db = @mysql_pconnect(BASESERVER, BASEUSER, BASEPASS))) //connect to base host
die("Cannot connect to the base server.");
if(!@mysql_select_db(BASENAME,$db)) //select base
die("Database doesn't exist!!!");
if(($result = @mysql_query($sql,$db)) == 0) //Execute SQL query
echo "\n<hr>Database error: <strong>".mysql_error()."</strong><br /><br />\n";
die("Query was (<strong>$sql</strong>) in file <strong>".$_SERVER["PHP_SELF"]."</strong>");
Also, you will notice my_query function which basically execute the given query. You will probably find id handy later on.
For now, functions file have this simple function which will add article in database.
* Simple function for adding article
* Function expects an array with article details
* it will perform all neccesary checks
* On error it will set session with error and return false
* On success, it will add record into database and return true
$_SESSION["error"] = "Please enter The Article Name";
$_SESSION["error"] = "Please enter a summary";
$_SESSION["error"] = "Please enter a content";
$sql = "INSERT INTO articles SET";
$sql .= " article_name = '".$data["article_name"]."'";
$sql .= ", summary = '".$data["summary"]."'";
$sql .= ", author = '".$data["author"]."'";
$sql .= ", article_content = '".$data["article_content"]."'";
$sql .= ", notes = '".$data["notes"]."'";
$sql .= ", date_added = NOW()";
$sql .= ", Status = '0'";
Now, your file which adds article in database should look like this:
This way you will have to include common.php in every file, but it really makes it easier this way.
$article["article_name"] = $_POST['articlename'];
$article["summary"] = $_POST['summary'];
$article["author"] = $_POST['author'];
$article["article_content"] = $_POST['bodycontent'];
$article["notes"] = $_POST['notes'];
//do whatever you want to do on succes
$_SESSION["article"] = $article;
This is first stage of course, and lots of changes can be done to all those files, but it's wise to go step by step
As for the sessions, they are good for usage for logging in users, but you should firstly decide where would you like to store username/password. I suggested htacces because it's the easiest way and it's just fine for the start.