Help Inserting data in mysql table


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help Inserting data in mysql table
# 1  
Old 03-30-2008
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  
Old 03-30-2008
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  
Old 03-30-2008
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  
Old 03-30-2008
Quote:
Originally Posted by redhead
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  
Old 03-30-2008
I found this page with a explanation how to insert dates in mysql, hope this helps:

MySQL Tutorial - Date

Regards
# 6  
Old 03-30-2008
You need to add the values in quotes
Code:
mysql -D "weather_wise" -e "INSERT INTO weather (Date, Hour, Degrees) VALUES ('$D','$H', '$temp')";

# 7  
Old 03-30-2008
Quote:
Originally Posted by Franklin52
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?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Send Data to MySQL Table Columns

I have two scripts, each script reads an individual data file and copies specific lines of data and sends to MySQL table. Only difference is, each script sends data to a separate column on the same DB. I want to use one script to populate DB table and have data look horizontal, with no overlapping.... (3 Replies)
Discussion started by: SysAdminRialto
3 Replies

2. Programming

MYSQL merge csv data with exisiting table

I have a MYSQL table with demographic data. The addresses contained in the table were entered manually before the advent of online postcode lookup software and, hence, there are a lot of errors when using automated online mailing checking software. I plan to export the data as csv file for a 3rd... (1 Reply)
Discussion started by: barrydocks
1 Replies

3. Shell Programming and Scripting

Error inserting a clob file into DB table

Hi all, I am reading control file log from my server and putting it to a variable for j in $(cat $dirname/ctl_file.log) do if then Y=${#fileclob_ctl_file} if then fileclob_ctl_file=$j else fileclob_ctl_file="${fileclob_ctl_file},${j}" fi fi ... (5 Replies)
Discussion started by: Pratiksha Mehra
5 Replies

4. UNIX and Linux Applications

mysql table disappear

I have set a mysql file to excute everyday morning to generate a html file displayng 2 tables from the database. Sometime they cannot be shown, and it shows the tables are not existed. I have not drop any table, and those 2 tables are not used by any other excution. Anybody know what is happening?... (0 Replies)
Discussion started by: c203040
0 Replies

5. Shell Programming and Scripting

how to print out data from mysql table in perl script

I'm having trouble with this code. if i do .\read.pl -u user it prints out 2010-12-20 12:00:00 host1 <cmd>a 2010-12-20 12:00:01 host1 <cmd> <execute> 2010-12-20 12:00:02 host1 <cmd>b 2010-12-20 12:00:03 host1 <cmd>c however, if i enter .\read.pl -h host1 it should... (3 Replies)
Discussion started by: kpddong
3 Replies

6. Shell Programming and Scripting

inserting data into a table from a flat file

Hi, I want to insert data into a table from a flat file, the file is having around 25 columns and some 10,000 records. The columns values are seperated by a space. Thanks (1 Reply)
Discussion started by: ss_ss
1 Replies

7. Programming

API C MYSQL vs lock table ???

(sorry for my english) Hi, i have an app that uses MYSQL API C.. i trying do a timeout until the table is locked by an other thread , in the docs of Mysql i can see that MYSQL_OPT_READ_TIMEOUT is not implemented for linux ¿?¿?.. any body knows a way to do a timeout until the table is locked by... (0 Replies)
Discussion started by: JEscola
0 Replies

8. Shell Programming and Scripting

Inserting records from flat file to db table

I have 20000 numbers present in a file in each line like 25663, 65465, 74579, 56446, .. .. I have created a table in db with single number column in it. create table testhari (no number(9)); I want to insert all these numbers into that table. how can i do it? can anybody please... (4 Replies)
Discussion started by: Hara
4 Replies

9. Shell Programming and Scripting

Inserting Values From A File Into A Table

Guys, I want to insert some values from a log file into a temporary table. the values in the log file looks like this SV_NAME CC_NAME CP_DISP_RUN_STATE ------- ------------------- ----------------- sble01 ALLTEL WorkMon24Hrs Running I want to enter the... (2 Replies)
Discussion started by: ragha81
2 Replies

10. Shell Programming and Scripting

MySql: create table error

Hi, iam learning MySql. Iam trieing to create a table in the database "guestbook" at the command line in mysql heres what i type but i get a error mysql>create table guestbook ->( -> name varchar(40) null. -> url varchar(40) null. -> comments ... (3 Replies)
Discussion started by: perleo
3 Replies
Login or Register to Ask a Question