Solved

PHP MySQL Insert Query Issue on Time Field

Posted on 2008-06-21
9
467 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: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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

785 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