Solved

PHP MySQL Insert Query Issue on Time Field

Posted on 2008-06-21
9
469 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

726 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