Okay,
I am fairly new to PHP and am having a very hard tme figuring out what I would need to change in order to make this work. Basically this will be a messaging system on my website between a client and myself.
The problem is, as it stands now, everytime that I go to the page or refresh the page it posts a blank message. I only want it to post if there is content in the message field and if the user hits the submit button.
The code is:
<?php
session_start();
if(!isset($_SESSION['username'])){
header( 'Location: loginform.html' );
}
require('db.php');
$client_ID = mysql_query("SELECT client_ID
FROM clients WHERE username='".$_SESSION['username']."'")or die(mysql_error());
$client_ID = mysql_fetch_array($client_ID);
$client_ID = $client_ID['client_ID'];
mysql_query("
INSERT INTO noteboard(client_ID, date, message)
VALUES('$client_ID', CURDATE(), '$_POST[message]')
");
// Displays all current notes
$getNotes = mysql_query("SELECT * FROM noteboard WHERE client_ID='".$client_ID."' ORDER BY date");
while($row = mysql_fetch_array($getNotes, MYSQL_ASSOC)){
echo "Posted by " . $_SESSION['username'] . " on " . $row['date'] . "<br /><p>"
. $row['message'] . "</p><hr />";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<form action="noteboard.php" method="post">
<h3>Message:</h3><br />
<textarea name="message" cols="30" rows="10"></textarea><br />
<input type="submit" value="Submit" /></form>
</body>
</html>