PDA

View Full Version : Date stamp



Lageo04
08-12-2006, 04:06 PM
I've created a registration page using David's contact mail-to form.
I've added lines to the processing page to also enter data into my sql.
All is working great.
I'd like to add a date stamp to the data base. I've already added the column to my data table in My Sql. Now I don't know what I need to add to the processing page to make this entry happen.
It's probably a simple line but I don't have a clue.
Thanks in advance
George

davidundalicia
08-12-2006, 07:31 PM
Hi Lageo04

Have you included the date field/s in your php file ?

Lageo04
08-12-2006, 08:24 PM
Hi David:
That's where I'm lost. I know the process page has to have something in it so it can enter the date data into my sql.
This is the process page:

<?PHP
// Receiving variables
@$firstname = addslashes($_POST['firstname']);
@$lastname = addslashes($_POST['lastname']);
@$username = addslashes($_POST['username']);
@$email = addslashes($_POST['email']);
@$comments = addslashes($_POST['comments']);
$commentsl = ereg_replace('@', '(.)', $commentsl);
// error checking
if (strlen($firstname) == 0 )
{
header("Location: name_error.html");
exit;
}
if (strlen($lastname) == 0 )
{
header("Location: name_error.html");
exit;
}
if (strlen($username) == 0 )
{
header("Location: user_error.html");
exit;
}
if (strlen($email) == 0 )
{
header("Location: email_error.html");
exit;
}
if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email))
{
header("Location: email_error.html");
exit;
}
if (substr_count($comments, '@') > "2")
{
header("Location: comments_error.html");
exit;
}
//Sending Email to form owner
$mailto = "xxxxxxx@xxxxxxx";
$mailsubj = "Feedback from My website form";
$mailhead = "From: $email\n";
reset ($HTTP_POST_VARS);
$mailbody = "Values submitted from my web site form:\n";
while (list ($key, $val) = each ($HTTP_POST_VARS))
{
$mailbody .= "$key : $val\n";
}
mail($mailto, $mailsubj, $mailbody, $mailhead);
$link = mysql_connect("localhost","xxxxxxx","xxxxxxxx");
mysql_select_db("xxxxxxxx_frgn1",$link);
$query="insert into members (first_name,last_name,user_name,email,comments) values ('".$firstname."','".$lastname."','".$username."','".$email."','".$comments."')";
mysql_query($query);

header("Location: confirmationpage.html");
?>

I'm not even sure if something has to be in the form page also.
Any help will be appreciated.
Thanks George

davidundalicia
08-12-2006, 09:45 PM
There must be a database command which would add
the date but if you add the 3 lines as seen below in receiving variables
it should work............

You will also have to add these 3 fields to your form as well

day
month
year

Lastly you will have to add them to your database code....

have fun, and please let us know how you get on.


// Receiving variables
@$firstname = addslashes($_POST['firstname']);
@$lastname = addslashes($_POST['lastname']);
@$username = addslashes($_POST['username']);
@$email = addslashes($_POST['email']);
@$comments = addslashes($_POST['comments']);
@$day = addslashes($_POST['day']);
@$month = addslashes($_POST['month']);
@$year = addslashes($_POST['year']);

Lageo04
08-12-2006, 11:16 PM
That would be the easy way, but I like to make things difficult.
I'm looking for a way to date stamp when the form is filled out so that it will automatically enter the date in the data base.
If I'm right, there has to be some sort of code in the form page to pickup the current date so it can be processed for entry into the database without having to be manually inserted in the form page.

navaldesign
08-13-2006, 07:33 AM
Ok, it depends on many things. Some use the "time" but in that case you would need some lines of code to convert time in a recognizable format (time is simply a number). So i suggest you do this:

Add this line in your script, anywhere before the DB writing part:

$date = date("l jS F Y, g:i A");

Then add the string $date in your database, excactly as you do for the other strings.

The code should be in the script, NOT in the form. Of course, this will give you the server date and time, if there is time difference between your location time and the server time, you will need some times of code to correct this difference (if it is so important) .