I am still figuring out PHP and I now know that I need to use the mysql_real_escape_string() in some way. The problem is, I cannot figure out how to use it. My code is as follows:
<?php
session_start();
if(!isset($_SESSION['username'])){
header( 'Location: loginform.html' );
}
require('db.php');
$query_client_ID = sprintf("SELECT client_ID FROM clients WHERE username='".$_SESSION['username']."'",
mysql_real_escape_string($username));
$client_ID = mysql_query($query_client_ID);
$client_ID = mysql_fetch_array($client_ID);
$client_ID = $client_ID['client_ID'];
if (isset($_POST['Submit'])) { // if the form has been submitted
if ($_POST[message]!="") { // if the message isn't blank
mysql_query("
INSERT INTO noteboard(`client_ID`, `date`, `message`)
VALUES('$client_ID', CURDATE(), '$_POST[message]')
") or die(mysql_error());
}
}
// Displays all current notes
$query = sprintf("SELECT * FROM noteboard WHERE client_ID='".$client_ID."' ORDER BY date",
mysql_real_escape_string($client_ID));
$getNotes = mysql_query($query);
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" name="Submit" value="Submit" /></form>
</body>
</html>
Any help would be greatly appreciated!