Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP MySQL Insert Query Issue on Time Field

Posted on 2008-06-21
9
Medium Priority
?
474 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…
Suggested Courses

596 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