i am trying to insert data to my PostgreSQL table, i am getting date as string from form, but i end up with this error
ERROR: malformed array literal: "" LINE 2: ...d','2018-07-27 00:00:00','2018-07-27 00:00:00','','',1,1,'',... ^ DETAIL: Array value must start with "{" or dimension information.
this is my query
insert into events (title,location,description,start_date,end_date,start_time,end_time,is_pet,is_child,untill,repeat) values ('test','asdasd','asdasd',2018-07-27 00:00:00,2018-07-27 00:00:00,'','',1,1,'','Does Not Repeat')
and my query is parsed like this
$query = "insert into events (title,location,description,start_date,end_date,start_time,end_time,is_pet,is_child,untill,repeat) values
('$title','$location','$description',$start_date,$end_date,'$start_time','$end_time',$is_pet,$is_child,'$until','$repeat')";
$sql = pg_query($query);
if (!$sql) {
echo pg_last_error($db);
} else {
echo "Records created successfully\n";
}
My Schema as follows
CREATE TABLE public.events (
id integer NOT NULL,
title character varying(255),
location character varying(255),
description character varying(255),
end_date timestamp without time zone,
start_time character varying(20),
end_time character varying(20)[],
image character varying(500),
is_pet boolean,
is_child boolean,
repeat character varying,
created_at timestamp without time zone,
updated_at timestamp without time zone,
posted_by character varying(255),
email character varying(255),
untill date,
start_date timestamp without time zone
);
end_timeis an array. Presumably that's a mistake as it makes no sense. That's why PG is complaining, you're giving it something that is not an array and it's telling you an array must start with{$start_dateand$end_date. However, a better solution would to do this with prepared statements, so that you don't have to worry about proper quoting and escaping of data in a sql query. Begin with pg_prepare.