Page 1 of 1

insert date/time from a webpage on my site into mysql

Posted: Tue May 19, 2009 8:09 am
by daiyan
hi ok i know how to insert data into a mysql using forms and php scripts but i would like to insert date/time from a webpage on my site into mysql.
The date/time are auto generated and displayed on my webpage via a php scipt that is running on the webpage.

Is there a way to include the output of the date/time php script in the the rest of the form that follows it i.e so when users enter their name and a image and click upload the date/time will also be passed on to the php script that inserts the name/image into the mysql.

just to recap i have a webpage with a form where users enter their name/image and click uplaod and the values get passed to a php script that inserts the values into mysql but i would like the date/time that is being displayed on the same page to be passed on to the insert php script aswell.

i cant use the timestamp option in my mysql to auto generate the date/time as the server of mysql is in the usa and iam in the uk and so the date/time recorded is always wrong and as iam using a free host so i cant change the server time zone via .htaccess or php.ini or any other way till i upgrade and pay for hosting which i dnt want to do as iam just learning at the moment.

below is the time.php script that generates and displays the date/time on my website and also below is the simple form script on the same page.

hope some one can help.

Code: Select all

 
<?php
 
$hourdiff = "14"; // hours difference between server time and local time
$timeadjust = ($hourdiff * 3600);
$melbdate = date("l, d F Y h:i a",time() + $timeadjust);
print ("$melbdate");
 
?>
 

form script

Code: Select all

 
<form method="post" enctype="multipart/form-data" action="file-upload.php">
  <div><?php echo $message; ?></div><?php echo $max_file_size_tag; ?>
Name: <input name="name" type="text"><br>
Please select file to upload: <input type="file" size="20" name="filename">
  <input type="submit" value="Upload" name="submit">
</form>
 

Re: insert date/time from a webpage on my site into mysql

Posted: Tue May 19, 2009 9:25 am
by jaoudestudios
Put the date time stamp in a hidden field in the form and just collect it and insert it into the database as you do everything else.

i.e.

Code: Select all

<input type="hidden" name="date" value="<?php echo $meldate; ?>" />

Re: insert date/time from a webpage on my site into mysql

Posted: Tue May 19, 2009 11:03 am
by daiyan
OK i have tried that and it seems like it should work but it is not and that prob because i dont know how to get the php script for the date/time to intgrate into the form itself.
what i mean is how do i get the bit in the form where it says

Code: Select all

<input type="hidden" name="date" value="<?php echo $meldate; ?>" />
to adopt the output of the php script for the date/time i.e how do i get $meldate to take the value from php date/time script outputted if you see what i mean. thank u for what u said so far tho and it seems like it would work if i was not so bad at php.

oh yaeh when i tried what you said it all seemed to run ok but the date column in my mysql stayed emty.

Re: insert date/time from a webpage on my site into mysql

Posted: Tue May 19, 2009 11:24 am
by divito
Your first piece of code says "$melbdate" yet I think you copied jaoudestudios' code that is missing the 'b' in $melbdate. Perhaps that's the issue?

Re: insert date/time from a webpage on my site into mysql

Posted: Tue May 19, 2009 12:22 pm
by daiyan
hey thanx for that it works like a dream xcept for on the webpage where u can upload name/iamge and where the date php script is there is a warning message saying "Suspicious file name or could not determine file extension." i think its something to do with my php script that inserts the data into mysql, that php script also checks the allowed file types so iam not sure what i should do i need that function to make sure that files that could harm my website dont get uploaded but wod like to get rid of that notice even tho the whole thing works fine but would prefer not to have that message but thank you anyways.

Re: insert date/time from a webpage on my site into mysql

Posted: Tue May 19, 2009 12:28 pm
by jaoudestudios
divito wrote:Your first piece of code says "$melbdate" yet I think you copied jaoudestudios' code that is missing the 'b' in $melbdate. Perhaps that's the issue?
Well spotted!

Glad it works :)

Re: insert date/time from a webpage on my site into mysql

Posted: Tue May 19, 2009 12:57 pm
by daiyan
definantly well spotted eagle eyes cheers

Re: insert date/time from a webpage on my site into mysql

Posted: Tue May 19, 2009 2:17 pm
by Benjamin
@daiyan,
Forum Rules wrote: 11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.
You may also want to read:
  1. General Posting Guidelines
  2. Posting Code in the Forums
  3. PHP Manual
  4. PHP Tutorials