Current location: Hot Scripts Forums » Programming Languages » PHP » Date problem


Date problem

Reply
  #1 (permalink)  
Old 04-04-04, 06:23 AM
Merovingian's Avatar
Merovingian Merovingian is offline
Newbie Coder
 
Join Date: Jan 2004
Location: Los Angeles
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Question Date problem

Yaooo
Ive recently made a news script from scratch but I encountered a wee little problem:
PHP Code:

if($r)

{
$today date("F j, Y, g:i a");                        
$sql "INSERT INTO XXX( `entry_date` , `username` , `entry_title` , `entry`)";
$sql .= "VALUES (' "$today " ' , ' " $user " ' ,'  " $title" ' ,'  " $entry " ')";
$ret mysql_query($sql);
if(!(
$r))
{
printf(" An Error occured...");
print 
mysql_error();

.
Now the problem with the script is that it doesnt seem to input the actual date and time unto the row thats in MySQL ergo giving me nothing but0000-00-00 00:00 when it is viewed.
But weird it is that i have another similar script that has the same line but is actually inserting it into the row of where it should be situated in.

can somone help me with this one ?
Is there a better way to actually input the proper date and time into MySQL than what I am already utilizing?

Thank you all for your counsel.


}
__________________
"Duo seguere aut de via decede" ...
Reply With Quote
  #2 (permalink)  
Old 04-04-04, 07:51 AM
Bonzo's Avatar
Bonzo Bonzo is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 340
Thanks: 0
Thanked 0 Times in 0 Posts
Thought

I am new to php but I have noticed that you have at the top of your code if ($r) should this be something like if ($r == 1)

I am using this in one of my uploads - the variables are passed in a form.

$result2 = mysql_query ("INSERT INTO photos (image, date, person, text )
VALUES ('$image', '$date', '$person', '$text' )");


Anthony

Last edited by Bonzo; 04-04-04 at 07:54 AM.
Reply With Quote
  #3 (permalink)  
Old 04-04-04, 12:11 PM
AvanteGuard AvanteGuard is offline
Newbie Coder
 
Join Date: Feb 2004
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Personally I hate moving times between php and sql format. Timestamps seem to work the best for me! But if you want to do it your date string should look like:

PHP Code:



$today 
date("Y-m-d H:i:s"); 
that would return 2004-04-04 13:12:46 (the format I believe your date is in.)

oh and Bonzo, if($r) means that if($r!=false) (If $r is not equal to false, 0 or null)
__________________
Looking for Fast Professional Programming, Delivered ON TIME and at a great price? Then we're your team! Check us out at http://www.imadigan.com

ICQ: 314-942-262 / 111-638-053
MSN: matt@imadigan.com
Reply With Quote
  #4 (permalink)  
Old 04-04-04, 12:55 PM
Bonzo's Avatar
Bonzo Bonzo is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 340
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for the info AvanteGuard its nice to learn something new.

Anthony
Reply With Quote
  #5 (permalink)  
Old 04-04-04, 03:12 PM
Merovingian's Avatar
Merovingian Merovingian is offline
Newbie Coder
 
Join Date: Jan 2004
Location: Los Angeles
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Great

Got it to work I had the wrong date code for datetime!
Ergo everything was not functioning due to that minuscule error in $today.
But now it is thanks guys.
__________________
"Duo seguere aut de via decede" ...
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with date in combobox. Periodically lose valu Danie Visual Basic 1 03-04-04 02:41 PM
date question darkcarnival PHP 1 10-22-03 08:12 PM
Date From Access 2000 Database Kaikki ASP 4 09-25-03 06:04 PM
selection of dup recs by latest date atworx Hot Scripts Forum Questions, Suggestions and Feedback 0 06-24-03 11:05 PM
Days left to certain date. Data from MySQL alfreds PHP 4 06-17-03 09:26 AM


All times are GMT -5. The time now is 10:23 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.