PHP is submiiting blank data

Permabanned
Joined
22 Apr 2007
Posts
1,805
yo!

Thanks to help from this very site, I have the following code

Code:
<?php
session_start();
if(!$_SESSION['username']) {
       //not logged in. redirect to login page
       header("Location: login.php");
       exit;
}

$p_title = $_POST['title'];
$p_menu_title = $_POST['menutitle'];
$p_summary = $_POST['summary'];
$p_body = $_POST['body'];

$address = "localhost";
$username = "mark1e_bourne";
$password = "you_wish";
$database = "mark1e_bourne";

mysql_connect($address,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO news (p_title, p_menu_title, p_summary, p_body) VALUES ('$p_title','$p_menu_title','$p_summary','$p_body')";
mysql_query($query);

mysql_close();

?>

directly above my HTML form

When I click update, the information is submitted accurately, but also, another entry is made which is completely blank.

Why is this? What do I need to add to the code to stop this happening?

The part at the top:-

Code:
]<?php
session_start();
if(!$_SESSION['username']) {
       //not logged in. redirect to login page
       header("Location: login.php");
       exit;
}
is used because this is the first page presented after a successful login.

Any help, as always, greatly appreciated.

Thanks
 
OK, thanks guys, I'm really just being thrown in at the deepend here. My problem is I need to understand why the data is appearing, not just the code to solve it, and some of you are kind enough to point that out to me in simpler language which I am very greatful for.

Thanks again
 
Back
Top Bottom