Solved

PHP MySQL Insert Query Issue on Time Field

Posted on 2008-06-21
9
470 Views
Last Modified: 2010-05-18
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,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',,'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','dfg',1,1,'1',,NOW(),'http://',0,0,0,NOW(),0,0,0,0,0,0,''' at line 1




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,'')";

Open in new window

0
Comment
Question by:kallestie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 28

Expert Comment

by:gamebits
ID: 21839131
Change

category',,NOW(),'

for

category',NOW(),'
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 21839143
The date in the SQL is not shown as being in quotes.
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 21839164
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,
      ''
      )
0
Webinar: MongoDB® Index Types

Join Percona’s Senior Technical Services Engineer, Adamo Tonete as he presents “MongoDB Index Types, How, When and Where Should They be Used?” on Wednesday, July 12, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7).

 
LVL 2

Author Comment

by:kallestie
ID: 21839177
I changed it to:

      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,'')";

and it returns

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',,'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 'NOW(),'http://',0,0,0,NOW(),0,0,0,0,0,0,'')' at line 1
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 21839195
You still have a double comma before NOW().
0
 
LVL 2

Author Comment

by:kallestie
ID: 21839201
Thank you, now I am getting:

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',,'14:00:00','fdg','fdg','dfg',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
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 21839220
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)
0
 
LVL 15

Accepted Solution

by:
mr_egyptian earned 500 total points
ID: 21839231
If this shows the line  numbers correctly, you have 29 columns, and only 27 values.
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 
 
'',
'0',
'fghgfh',
'fghgfh',
'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,
''

Open in new window

0
 
LVL 2

Author Comment

by:kallestie
ID: 21839246
AI am still miscounting! ARGH!@!!!!!

      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',0,NOW(),'$contactURL',0,0,0,NOW(),0,0,0,0,0,$cost,'')";

which returns

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','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
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question