Solved

PHP MySQL Insert Query Issue on Time Field

Posted on 2008-06-21
9
460 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
9 Comments
 
LVL 28

Expert Comment

by:gamebits
ID: 21839131
Change

category',,NOW(),'

for

category',NOW(),'
0
 
LVL 40

Expert Comment

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

Expert Comment

by:RQuadling
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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 40

Expert Comment

by:RQuadling
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:RQuadling
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now