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

03-15-2007, 06:21 AM
the variable vlues are:
$trans_date = getdate();
$theAmmount = 20;
$trans_date2 = getdate();

the query is:
if(!mysql_query("insert into transaction(source,destination,amount,date,strt_time,end_time,status)

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
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);

03-15-2007, 08: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).