The UNIX and Linux Forums  

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 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 12:35 AM
inserting into a data file paul1s UNIX for Dummies Questions & Answers 4 10-12-2006 11:47 PM
Inserting Values From A File Into A Table ragha81 Shell Programming and Scripting 2 09-16-2006 04:10 PM
Editing a mySQL table on a remote machine Sn33R UNIX for Dummies Questions & Answers 6 10-13-2003 10:47 PM
MySql: create table error perleo Shell Programming and Scripting 3 04-16-2003 02:23 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 03-30-2008
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
Reply With Quote
Forum Sponsor
  #2  
Old 03-30-2008
redhead's Avatar
Registered User
 

Join Date: Feb 2002
Location: Denmark
Posts: 48
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.
Reply With Quote
  #3  
Old 03-30-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,199
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
Reply With Quote
  #4  
Old 03-30-2008
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
Reply With Quote
  #5  
Old 03-30-2008
Moderator
 

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

MySQL Tutorial - Date

Regards
Reply With Quote
  #6  
Old 03-30-2008
redhead's Avatar
Registered User
 

Join Date: Feb 2002
Location: Denmark
Posts: 48
You need to add the values in quotes
Code:
mysql -D "weather_wise" -e "INSERT INTO weather (Date, Hour, Degrees) VALUES ('$D','$H', '$temp')";
Reply With Quote
  #7  
Old 03-30-2008
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?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:55 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0