...

View Full Version : creating a new entry in a table using variales and getDate function



aconite
03-15-2007, 07:21 AM
the variable vlues are:
$trans_date = getdate();
$tran_source=5487335;
$thePswd=1111;
$theDest=1234567;
$theAmmount = 20;
$trans_date2 = getdate();


the query is:
if(!mysql_query("insert into transaction(source,destination,amount,date,strt_time,end_time,status)
values($transSource,$theDest,$theAmmount,trans_date[mday]:$trans_date[mmon]:$trans_date[year],trans_date[seconds]:$trans_date[minutes]:$trans_date[hours],trans_date2[seconds]:$trans_date2[minutes]:$trans_date2[hours],TRUE)")

{
echo "query not executed";
}


i want the date to be displayed in dd:mm:yy
i know the prob is in the query syntax but i cant understand how to use the getDate func and also shld i use '$tranSource'??

data types given when the table was created:

CREATE TABLE transaction
(id INT(4) AUTO_INCREMENT NOT NULL PRIMARY KEY,
source INT(7) UNSIGNED,
destination INT(7) UNSIGNED,
amount INT(3) NOT NULL,
date DATE ,
strt_time TIME ,
end_time TIME ,
status ENUM(\"TRUE\",\"FALSE\") NOT NULL);

Fumigator
03-15-2007, 09:26 AM
Your code has simple syntax errors that you need to flush out. Be sure to enclose index names with quotes (i.e. $trans_date['hour'], not $trans_date[hour]) and one or two of your variables are missing the dollar sign. You also need to enclose the variables in squiggly brackets when they are complex variables (i.e. {$trans_date['hour']}, not $trans_date['hour']).

And finally to your point-- the query is an insert query, so it's not going to "display" in any format. Once you have data in a datetime data type, you can format it to be displayed any dang way you feel like with the MySQL function date_format() (http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum