<?php
//connexion to mysql Database
require_once('../tdi_includes/session.php');

if(isset($_POST['submit']) && $_POST['send']=="send"){
				 	if(isset($_SESSION['idm']) && isset($_SESSION['logedin'])){
							$msg=preper_data($_POST['msg']);
							if($msg != "" && $msg!= "write an message..."){
								//insert the message into the database
								$cmd="insert into message values('','".$msg."')";
								$result=mysql_query($cmd);
								//in order to check the query
								check_result($result); 
							}
					}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" >
<title>Ecrire un Message</title>
</head>
<body>
			<form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">						
						<textarea name="msg"   style="width: 430px; height: 60px" id="msg">write an message...</textarea><br>
						<input type="hidden" name="send"  value="send" >
						<input name="submit" type="submit" value="Envoyer"  class="modifier">			
			</form>
			<!-- print all messages-->
			<?php
			$cmd="select * from message order by id_msg desc";
			$result=mysql_query($cmd);
			//in order to check the query
			check_result($result); 
			if(mysql_num_rows($result) > 1){
				while($msg=mysql_fetch_array($result)){
			?>
				<div style="background:#D3E2E1">
					<?php echo $msg['msg']; ?>
				</div>
					<hr>
			<?php
				}//while
			}//if
			?>

</body>

</html>
