what i have so far is data coming from a text box, the user also can select which tables they would like to insert that data into, (up to 4 seperate tables). after its submitted the code checks if the record exists, if not it inserts the data into the correct tables along with the current timestamp..
what i need is after it checks if the record exists. if the record exists i need t check the timestamp compared to the current time.. if the current time is greater than the timestamp by 1 hour (or any other number of minutes i specify. then i want to move that record to the top of list..
if it has Not been greater than the specified time i want to display how many minutes are left before they can move there entry to the top of the list.
Ive never worked with timestamps before can someone please give me some insight. Also the timestamp is stored in the table column "time"
Thanks,
<?php
require('FC_DB_connection.php');
//check if form has been submited
if(isset($_POST['submit'])){
//new code sent from form
$textbox_value = ($_POST['code']);
$checkbox = ($_POST['checkbox']);
// To protect MySQL injection
$textbox_value = stripslashes($textbox_value);
$textbox_value = mysql_real_escape_string($textbox_value);
//process data and insert into database
foreach($checkbox as $tablename) {
//check if record exists
$checkcode = "(SELECT count(*) FROM $tablename WHERE code ='$textbox_value')";
$check = mysql_query($checkcode);
$check_result = mysql_fetch_row($check);
$check_result = $check_result['0'];
//need to pull time stamp from database.
//if current time is greater than 1 hour of timestamp.
//then move $textbox_value to top of the list.
//if Not then display how much time is left before hour is up.
if($check_result >0)
{
echo '<table bgcolor="#cccccc" border="1">';
echo '<tr><td width="400">';
echo "Your code has already been added to the $tablename database.";
echo "</td></tr>";
echo "</table>";
}
else
{
$query = "INSERT INTO $tablename (code, time) VALUES ('$textbox_value', NOW())";
$result = mysql_query($query) or die(mysql_error());
if($result) {
echo '<table bgcolor="#cccccc" border="1">';
echo '<tr><td width="250">';
echo "code added to $tablename Database";
echo "</td></tr>";
echo "</table>";
}
else
echo "could not add code to $tablename Database <br />";
}
}
?>