post/get date to/from sql

i am building a messaging system with a frined in php and mysql and im trying to get it to post the date when the new message is posted this is my send code

[php]<?php include 'header.php' ?>

<?php if(isset($_GET['user']) && !empty($_GET['user'])){ ?>
<form method='post'>
<?php
if(isset($_POST['message']) && !empty($_POST['message'])){
		$my_id = $_SESSION['user_id'];
		$user = $_GET['user'];
		$random_number = rand();
		$message = $_POST['message'];
		$timedate = strtotime("now");
		$check_con = mysql_query("SELECT hash FROM message_group WHERE (user_one='$my_id' AND user_two='$user') OR (user_one='$user' AND user_two='$my_id')");
	
	if(mysql_num_rows($check_con) == 1){
		echo '<p>Conversation Already Started</p>';
		
	} else {
	mysql_query("INSERT INTO message_group VALUES('$my_id', '$user', '$random_number', '$timedate')");
	mysql_query("INSERT INTO messages VALUES('', '$random_number', '$my_id', '$message'") ;
		
		echo "<p>Conversation Started</p>'$timedateetc'/'$timedateetc1'";
		}
}
?>
Enter Message: <br />
<textarea name='message' rows='7' cols='60'></textarea>
<br /><br />
<input type='submit' value='Send Message' />
</form>

<?php
	
} else {
	echo '<b>Select User</b>';
	$user_list = mysql_query("SELECT id, username FROM users");
	while($run_user = mysql_fetch_array($user_list)){
			$user = $run_user['id'];
			$username = $run_user['username'];
			
			echo "<p><a href='send.php?user=$user'>$username</a></p>";
			
	}
	
}

?>
Go Back

<?php include 'confooter.php' ?>[/php]

and on the next bit of code is where it checks for new messages but i want it to show the messages receved in the last 14 days and not show anything older then 14 days

[php]<?php include 'message_title_bar.php'; ?>

<?php $my_id = $_SESSION['user_id'] ?> <?php if(isset($_GET['hash']) && !empty($_GET['hash'])){ $hash = $_GET['hash']; $message_query = mysql_query("SELECT from_id, datetime, message FROM messages WHERE group_hash='$hash'"); while($run_message = mysql_fetch_array($message_query)){ $from_id = $run_message['from_id']; $message = $run_message['message']; $user_query = mysql_query("SELECT username FROM users WHERE id='$from_id'") or die(mysql_error()); $run_user = mysql_fetch_array($user_query); $from_username = $run_user['username']; echo "

$from_username
$message

"; } ?>
		<br />
		<form method='post'>
		<?php
		if(isset($_POST['message']) && !empty($_POST['message'])){
			$new_message = $_POST['message'];
			mysql_query("INSERT INTO messages VALUES('', '$hash', '$my_id', '$new_message')");
			header('location: conversation.php?hash='.$hash);
			
			
		}
		?>
		Enter Message: <br />
		<textarea name='message' rows='6' cols='50'></textarea>
		<br /><br />
		<input type='submit' value='Send Message' />
		</form>
		 <button onclick="goBack()">Go Back</button>
		<?php
	
} else {
	echo "<br /><b>Select Conversation :</b>";
	$get_con = mysql_query("SELECT hash, user_one, user_two FROM message_group WHERE user_one='$my_id' OR user_two='$my_id' AND datetime > '$timestamp'");
	while($run_con = mysql_fetch_array($get_con)){
		$hash = $run_con['hash'];
		$user_one = $run_con['user_one'];
		$user_two = $run_con['user_two'];
		$timestamp = strtotime("-14 days");
		if($user_one == $my_id){
			$select_id = $user_two;
			
		} else {
			$select_id = $user_one;
			
		}
		$user_get= mysql_query("SELECT username FROM users WHERE id='$select_id'");
		$run_user = mysql_fetch_array($user_get);
		$select_username = $run_user['username'];
		
		
		echo "<p><a href='conversation.php?hash=$hash'>$select_username</a></p>";
	echo "$timestamp";
		
	}
	
}

?>[/php]

Deprecated MySQL functions are simpler to use (not counting all the sanitizing you need to add) than PDO or MySQLi prepared statements, but far less secure. That’s why they’ve been deprecated. If you’re just learning PHP you should start with
PDO
and
Prepared Statements
When dealing with old code that uses deprecated MySQL functions you should replace them if possible. If it’s not possible, your experience with PDO or MySQLi will benefit you when dealing with MySQL functions.

Note that treating MySQLi like MySQL defeats the i in MySQLi.

managed to figger it out

[sup]WHERE datetime BETWEEN DATE_SUB( CURDATE( ) ,INTERVAL 14 DAY ) AND CURDATE( ) [/sup]

Glad to hear. You tend to remember how to do something more when you figure it out with trial and tribulation. The advisement of the deprecated code still stands however.

Sponsor our Newsletter | Privacy Policy | Terms of Service