The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Inserting records from flat file to db table Hara Shell Programming and Scripting 4 12-27-2006 03:35 AM
inserting into a data file paul1s UNIX for Dummies Questions & Answers 4 10-13-2006 02:47 AM
Inserting Values From A File Into A Table ragha81 Shell Programming and Scripting 2 09-16-2006 07:10 PM
Editing a mySQL table on a remote machine Sn33R UNIX for Dummies Questions & Answers 6 10-14-2003 01:47 AM
MySql: create table error perleo Shell Programming and Scripting 3 04-16-2003 05:23 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-30-2008
vadharah vadharah is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 27
Help Inserting data in mysql table

Cant understand the error

#!/bin/bash

temp=""
A=""

D=$(date +"%Y-%m-%d")
H=$(date +"%R")

temp=$(wget -q -O - website | grep -o "Temperature:[[:space:]]*[0-9][0-9]*" | grep \-E -o "[0-9]+")

mysql -D "weather_wise" -e "INSERT INTO weather (Date, Hour, Degrees) VALUES ($D,$H, $temp)";

my data types for Date an Hour are both date

Im getting error below i think on $D and $H......Please help me where am i going wrong

ERROR 1064 (42000) at line 1: 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 ':39, 7)' at line 1
  #2 (permalink)  
Old 03-30-2008
redhead's Avatar
redhead redhead is offline
Registered User
  
 

Join Date: Feb 2002
Location: Denmark
Posts: 67
The type DATE evaluates to only 'YYYY-MM-DD' when you try to insert your time stamp, it will be of the form 'HH:MM'
If you were to change the "Hour" portion of your able to be of type TIME you wouldn't have any trouble inserting your 'HH:MM' into your table.
  #3 (permalink)  
Old 03-30-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
I'm not familiar with myslq but perhaps you must convert the date and time with makedate() and maketime() before you can inserting them.

Regards
  #4 (permalink)  
Old 03-30-2008
vadharah vadharah is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 27
Quote:
Originally Posted by redhead View Post
The type DATE evaluates to only 'YYYY-MM-DD' when you try to insert your time stamp, it will be of the form 'HH:MM'
If you were to change the "Hour" portion of your able to be of type TIME you wouldn't have any trouble inserting your 'HH:MM' into your table.
i have tried that but same error though
  #5 (permalink)  
Old 03-30-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
I found this page with a explanation how to insert dates in mysql, hope this helps:

MySQL Tutorial - Date

Regards
  #6 (permalink)  
Old 03-30-2008
vadharah vadharah is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 27
Quote:
Originally Posted by Franklin52 View Post
I found this page with a explanation how to insert dates in mysql, hope this helps:

MySQL Tutorial - Date

Regards
Franklin52 thanks for that was very helpful.....

would you know how to limit time to only hour and minute?
  #7 (permalink)  
Old 03-30-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
Insert the time in this format:

Code:
'0000-0-0 04:13:00'
Regards
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:06 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0