kallestie
asked on
PHP MySQL Insert Query Issue on Time Field
Okay, so I know that no one else has this issue. :)
I have been staring at the same piece of PHP code for a while with some stupid syntax error and I cannot see the problem. I believe that is is a formatting issue with the time insert. I have successfully converted the time to military time and cannot seem to insert it into the time field of the database.
Any ideas?
This is the error:
INSERT INTO events (user,venue_id,title,descr iption,sta rt_date,en d_date,sta rt_time,tb d,end_time ,contact_n ame,contac t_email,co ntact_phon e,is_activ e,is_appro ved,catego ry,seriesI D,submitte d_at,conta ct_url,all ow_registe r,private, spaces_ava ilable,pub lish_date, views,dire ctions,dow nloads,ema il_to_frie nd,URLclic ks,cost,bu yURL) values('','0','fghgfh','fg hgfh
',1969-12-31,'13:00:00',,' 14:00:00', 'fdg','fdg ','dfg',1, 1,'1',,NOW (),'http://',0,0,0,NOW(),0,0,0,0,0,0,'')Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''14:00:00','fdg','fdg','d fg',1,1,'1 ',,NOW(),' http://',0,0,0,NOW(),0,0,0,0,0,0,''' at line 1
I have been staring at the same piece of PHP code for a while with some stupid syntax error and I cannot see the problem. I believe that is is a formatting issue with the time insert. I have successfully converted the time to military time and cannot seem to insert it into the time field of the database.
Any ideas?
This is the error:
INSERT INTO events (user,venue_id,title,descr
',1969-12-31,'13:00:00',,'
echo "INSERT INTO events (user,venue_id,title,description,start_date,end_date,start_time,tbd,end_time,contact_name,contact_email,contact_phone,is_active,is_approved,category,seriesID,submitted_at,contact_url,allow_register,private,spaces_available,publish_date,views,directions,downloads,email_to_friend,URLclicks,cost,buyURL) values('$user_id','$last_id','$eventTitle','$eventDescription',$eventDate,'$fullSTime',$tbd,'$fullETime','$contactName','$contactEmail','$contactPhone',1,1,'$category',,NOW(),'$contactURL',0,0,0,NOW(),0,0,0,0,0,$cost,'')";
$event_query = "INSERT INTO events (user,venue_id,title,description,start_date,end_date,start_time,tbd,end_time,contact_name,contact_email,contact_phone,is_active,is_approved,category,seriesID,submitted_at,contact_url,allow_register,private,spaces_available,publish_date,views,directions,downloads,email_to_friend,URLclicks,cost,buyURL) values('$user_id','$last_id','$eventTitle','$eventDescription',$eventDate,'$fullSTime',0,'$fullETime','$contactName','$contactEmail','$contactPhone',1,1,'$category',,NOW(),'$contactURL',0,0,0,NOW(),0,0,0,0,0,$cost,'')";
The date in the SQL is not shown as being in quotes.
INSERT INTO events
(
user,
venue_id,
title,
description,
start_date,
end_date,
start_time,
tbd,
end_time,
contact_name,
contact_email,
contact_phone,
is_active,
is_approved,
category,
seriesID,
submitted_at,
contact_url,
allow_register,
private,
spaces_available,
publish_date,
views,
directions,
downloads,
email_to_friend,
URLclicks,
cost,
buyURL
)
values
(
'',
'0',
'fghgfh',
'fghgfh',
'1969-12-31',
'13:00:00',
'', -- or 0 if this is a numeric column
'14:00:00',
'fdg',
'fdg',
'dfg',
1,
1,
'1',
'', -- or 0 id this is a numeric column,
NOW(),
'http://',
0,
0,
0,
NOW(),
0,
0,
0,
0,
0,
0,
''
)
(
user,
venue_id,
title,
description,
start_date,
end_date,
start_time,
tbd,
end_time,
contact_name,
contact_email,
contact_phone,
is_active,
is_approved,
category,
seriesID,
submitted_at,
contact_url,
allow_register,
private,
spaces_available,
publish_date,
views,
directions,
downloads,
email_to_friend,
URLclicks,
cost,
buyURL
)
values
(
'',
'0',
'fghgfh',
'fghgfh',
'1969-12-31',
'13:00:00',
'', -- or 0 if this is a numeric column
'14:00:00',
'fdg',
'fdg',
'dfg',
1,
1,
'1',
'', -- or 0 id this is a numeric column,
NOW(),
'http://',
0,
0,
0,
NOW(),
0,
0,
0,
0,
0,
0,
''
)
ASKER
I changed it to:
echo "INSERT INTO events (user,venue_id,title,descr iption,sta rt_date,en d_date,sta rt_time,tb d,end_time ,contact_n ame,contac t_email,co ntact_phon e,is_activ e,is_appro ved,catego ry,seriesI D,submitte d_at,conta ct_url,all ow_registe r,private, spaces_ava ilable,pub lish_date, views,dire ctions,dow nloads,ema il_to_frie nd,URLclic ks,cost,bu yURL) values('$user_id','$last_i d','$event Title','$e ventDescri ption','$e ventDate', '$fullSTim e',$tbd,'$ fullETime' ,'$contact Name','$co ntactEmail ','$contac tPhone',1, 1,'$catego ry',,NOW() ,'$contact URL',0,0,0 ,NOW(),0,0 ,0,0,0,$co st,'')";
$event_query = "INSERT INTO events (user,venue_id,title,descr iption,sta rt_date,en d_date,sta rt_time,tb d,end_time ,contact_n ame,contac t_email,co ntact_phon e,is_activ e,is_appro ved,catego ry,seriesI D,submitte d_at,conta ct_url,all ow_registe r,private, spaces_ava ilable,pub lish_date, views,dire ctions,dow nloads,ema il_to_frie nd,URLclic ks,cost,bu yURL) values('$user_id','$last_i d','$event Title','$e ventDescri ption','$e ventDate', '$fullSTim e',0,'$ful lETime','$ contactNam e','$conta ctEmail',' $contactPh one',1,1,' $category' ,,NOW(),'$ contactURL ',0,0,0,NO W(),0,0,0, 0,0,$cost, '')";
and it returns
INSERT INTO events (user,venue_id,title,descr iption,sta rt_date,en d_date,sta rt_time,tb d,end_time ,contact_n ame,contac t_email,co ntact_phon e,is_activ e,is_appro ved,catego ry,seriesI D,submitte d_at,conta ct_url,all ow_registe r,private, spaces_ava ilable,pub lish_date, views,dire ctions,dow nloads,ema il_to_frie nd,URLclic ks,cost,bu yURL) values('','0','fghgfh','fg hgfh
','1969-12-31','13:00:00', ,'14:00:00 ','fdg','f dg','dfg', 1,1,'1',,N OW(),'http://',0,0,0,NOW(),0,0,0,0,0,0,'')Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NOW(),'http://',0,0,0,NOW(),0,0,0,0,0,0,'')' at line 1
echo "INSERT INTO events (user,venue_id,title,descr
$event_query = "INSERT INTO events (user,venue_id,title,descr
and it returns
INSERT INTO events (user,venue_id,title,descr
','1969-12-31','13:00:00',
You still have a double comma before NOW().
ASKER
Thank you, now I am getting:
INSERT INTO events (user,venue_id,title,descr iption,sta rt_date,en d_date,sta rt_time,tb d,end_time ,contact_n ame,contac t_email,co ntact_phon e,is_activ e,is_appro ved,catego ry,seriesI D,submitte d_at,conta ct_url,all ow_registe r,private, spaces_ava ilable,pub lish_date, views,dire ctions,dow nloads,ema il_to_frie nd,URLclic ks,cost,bu yURL) values('','0','fghgfh','fg hgfh
','1969-12-31','13:00:00', ,'14:00:00 ','fdg','f dg','dfg', 1,1,'1',,N OW(),'http://',0,0,0,NOW(),0,0,0,0,0,0,'')Error: Column count doesn't match value count at row 1
INSERT INTO events (user,venue_id,title,descr
','1969-12-31','13:00:00',
Count out the columns against the values. There has to be the same number.
e.g.
insert into table(col1,col2,col3) values(val1,val2,val3)
not
insert into table(col1,col2,col3) values(val1,val2)
or
insert into table(col1,col2,col3) values(val1,val2,val3,val4 )
e.g.
insert into table(col1,col2,col3) values(val1,val2,val3)
not
insert into table(col1,col2,col3) values(val1,val2)
or
insert into table(col1,col2,col3) values(val1,val2,val3,val4
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
AI am still miscounting! ARGH!@!!!!!
echo "INSERT INTO events (user,venue_id,title,descr iption,sta rt_date,en d_date,sta rt_time,tb d,end_time ,contact_n ame,contac t_email,co ntact_phon e,is_activ e,is_appro ved,catego ry,seriesI D,submitte d_at,conta ct_url,all ow_registe r,private, spaces_ava ilable,pub lish_date, views,dire ctions,dow nloads,ema il_to_frie nd,URLclic ks,cost,bu yURL) values('$user_id','$last_i d','$event Title','$e ventDescri ption','$e ventDate', '$fullSTim e',$tbd,'$ fullETime' ,'$contact Name','$co ntactEmail ','$contac tPhone',1, 1,'$catego ry',,NOW() ,'$contact URL',0,0,0 ,NOW(),0,0 ,0,0,0,$co st,'')";
$event_query = "INSERT INTO events (user,venue_id,title,descr iption,sta rt_date,en d_date,sta rt_time,tb d,end_time ,contact_n ame,contac t_email,co ntact_phon e,is_activ e,is_appro ved,catego ry,seriesI D,submitte d_at,conta ct_url,all ow_registe r,private, spaces_ava ilable,pub lish_date, views,dire ctions,dow nloads,ema il_to_frie nd,URLclic ks,cost,bu yURL) values('$user_id','$last_i d','$event Title','$e ventDescri ption','$e ventDate', '$fullSTim e',0,'$ful lETime','$ contactNam e','$conta ctEmail',' $contactPh one',1,1,' $category' ,0,NOW(),' $contactUR L',0,0,0,N OW(),0,0,0 ,0,0,$cost ,'')";
which returns
INSERT INTO events (user,venue_id,title,descr iption,sta rt_date,en d_date,sta rt_time,tb d,end_time ,contact_n ame,contac t_email,co ntact_phon e,is_activ e,is_appro ved,catego ry,seriesI D,submitte d_at,conta ct_url,all ow_registe r,private, spaces_ava ilable,pub lish_date, views,dire ctions,dow nloads,ema il_to_frie nd,URLclic ks,cost,bu yURL) values('','0','ghfghgfh',' gfhgfhgf
','1969-12-31','13:00:00', ,'14:00:00 ','gfhsfh' ,'gfgfhgf@ fsfg.com', '',1,1,'1' ,,NOW(),'http://',0,0,0,NOW(),0,0,0,0,0,0,'')Error: Column count doesn't match value count at row 1
echo "INSERT INTO events (user,venue_id,title,descr
$event_query = "INSERT INTO events (user,venue_id,title,descr
which returns
INSERT INTO events (user,venue_id,title,descr
','1969-12-31','13:00:00',
category',,NOW(),'
for
category',NOW(),'