LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-17-2014, 12:33 AM   #1
aoiregion
LQ Newbie
 
Registered: Jul 2014
Posts: 11

Rep: Reputation: Disabled
Need help on Insert data to phpMyAdmin mySQL database


Hi guys, I hope that you guys could help me out, I have touched mysql, shell script & phpmyadmin for the first time last week. I would like to seek help on inserting data whenever the switch is on or off to my sensor mySQL database in phpMyAdmin from my Shell Script. I'm using Raspberry PI as my hardware and follow a few tutorials to create my own Web Control Interface, it works perfectly without insert method. After I implemented insert method to my GPIOServer.sh and execute it, an error stated that unexpected operator.

This is my GPIOServer.sh:
Code:
#!/bin/sh

mysqlusername="mysqlusername"
mysqlname="mysqlname"
mysqlpassword="mysqlpassword"

#Set  Refresh
echo "How long do you want the wait time to be?"
read waitTime

#Invoke GPIO
echo "4" > /sys/class/gpio/export
echo "17" > /sys/class/gpio/export
echo "18" > /sys/class/gpio/export
echo "21" > /sys/class/gpio/export
echo "22" > /sys/class/gpio/export
echo "23" > /sys/class/gpio/export
echo "24" > /sys/class/gpio/export
echo "25" > /sys/class/gpio/export

#Start Loop
while :
do
#Read MySQL Data
#Direction
direction4=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinDirection FROM pinDirection WHERE pinNumber='4'";)
direction17=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinDirection FROM pinDirection WHERE pinNumber='17'";)
direction18=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinDirection FROM pinDirection WHERE pinNumber='18'";)
direction21=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinDirection FROM pinDirection WHERE pinNumber='21'";)
direction22=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinDirection FROM pinDirection WHERE pinNumber='22'";)
direction23=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinDirection FROM pinDirection WHERE pinNumber='23'";)
direction24=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinDirection FROM pinDirection WHERE pinNumber='24'";)
direction25=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinDirection FROM pinDirection WHERE pinNumber='25'";)
#Status
status4=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinStatus FROM pinStatus WHERE pinNumber='4'";)
status17=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinStatus FROM pinStatus WHERE pinNumber='17'";)
status18=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinStatus FROM pinStatus WHERE pinNumber='18'";)
status21=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinStatus FROM pinStatus WHERE pinNumber='21'";)
status22=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinStatus FROM pinStatus WHERE pinNumber='22'";)
status23=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinStatus FROM pinStatus WHERE pinNumber='23'";)
status24=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinStatus FROM pinStatus WHERE pinNumber='24'";)
status25=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinStatus FROM pinStatus WHERE pinNumber='25'";)

#Run Commands
if [ "$direction4" == "out" ]; then
    echo "out" > /sys/class/gpio/gpio4/direction
    if [ "$status4" == "1" ]; then
        echo "1" > /sys/class/gpio/gpio4/value
        $(mysql --user=$mysqlname --password=$mysqlpassword sensor -e "INSERT INTO sensor(id, sensor, switchOnLog, switchOffLog) values('1', 'Red LED', $(date + %Y-%m-%d %T), '')";)
        echo "GPIO 4 Turned On"
    else
        echo "0" > /sys/class/gpio/gpio4/value
        $(mysql --user=$mysqlname --password=$mysqlpassword sensor -e "INSERT INTO sensor(id, sensor, switchOnLog, switchOffLog) values('1', 'Red LED', '', $(date + %Y-%m-%d %T))";)
        echo "GPIO 4 Turned Off"
    fi
else
    echo "in" > /sys/class/gpio/gpio4/direction
fi
if [ "$direction17" == "out" ]; then
        echo "out" > /sys/class/gpio/gpio17/direction
    if [ "$status17" == "1" ]; then
                echo "1" > /sys/class/gpio/gpio17/value
                $(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword sensor -e "INSERT INTO sensor values('2', 'Blue LED', $(date + %Y-%m-%d %T), '')";)
                echo "GPIO 17 Turned On"
        else
                echo "0" > /sys/class/gpio/gpio17/value
                $(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword sensor -e "INSERT INTO sensor values('2', 'Blue LED', '', $(date + %Y-%m-%d %T))";)
                echo "GPIO 17 Turned Off"
        fi
else
        echo "in" > /sys/class/gpio/gpio17/direction
fi
if [ "$direction18" == "out" ]; then
        echo "out" > /sys/class/gpio/gpio18/direction
    if [ "$status18" == "1" ]; then
                echo "1" > /sys/class/gpio/gpio18/value
                $(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword sensor -e "INSERT INTO sensor values('3', 'Green LED', $(date + %Y-%m-%d %T), '')";)
                echo "GPIO 18 Turned On"
        else
                echo "0" > /sys/class/gpio/gpio18/value
                $(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword sensor -e "INSERT INTO sensor values('3', 'Green LED', '', $(date + %Y-%m-%d %T))";)
                echo "GPIO 18 Turned Off"
        fi
else
        echo "in" > /sys/class/gpio/gpio18/direction
fi
if [ "$direction21" == "out" ]; then
        echo "out" > /sys/class/gpio/gpio21/direction
    if [ "$status21" == "1" ]; then
                echo "1" > /sys/class/gpio/gpio21/value
                $(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword sensor -e "INSERT INTO sensor values('4', 'Yellow LED', $(date + %Y-%m-%d %T), '')";)
                echo "GPIO 21 Turned On"
        else
                echo "0" > /sys/class/gpio/gpio21/value
                $(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword sensor -e "INSERT INTO sensor values('4', 'Yellow LED', '', $(date + %Y-%m-%d %T))";)
                echo "GPIO 21 Turned Off"
        fi
else
        echo "in" > /sys/class/gpio/gpio21/direction
fi
if [ "$direction22" == "out" ]; then
        echo "out" > /sys/class/gpio/gpio22/direction
    if [ "$status22" == "1" ]; then
                echo "1" > /sys/class/gpio/gpio22/value
                $(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword sensor -e "INSERT INTO sensor values('5', 'LED', $(date + %Y-%m-%d %T), '')";)
                echo "GPIO 22 Turned On"
        else
                echo "0" > /sys/class/gpio/gpio22/value
                $(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword sensor -e "INSERT INTO sensor values('5', 'LED', '', $(date + %Y-%m-%d %T))";)
                echo "GPIO 22 Turned Off"
        fi
else
        echo "in" > /sys/class/gpio/gpio22/direction
fi
if [ "$direction23" == "out" ]; then
        echo "out" > /sys/class/gpio/gpio23/direction
    if [ "$status23" == "1" ]; then
                echo "1" > /sys/class/gpio/gpio23/value
                $(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword sensor -e "INSERT INTO sensor values('6', 'LED', $(date + %Y-%m-%d %T), '')";)
                echo "GPIO 23 Turned On"
        else
                echo "0" > /sys/class/gpio/gpio23/value
                $(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword sensor -e "INSERT INTO sensor values('6', 'LED', '', $(date + %Y-%m-%d %T))";)
                echo "GPIO 23 Turned Off"
        fi
else
        echo "in" > /sys/class/gpio/gpio23/direction
fi
if [ "$direction24" == "out" ]; then
        echo "out" > /sys/class/gpio/gpio24/direction
    if [ "$status24" == "1" ]; then
                echo "1" > /sys/class/gpio/gpio24/value
                $(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword sensor -e "INSERT INTO sensor values('7', 'LED', $(date + %Y-%m-%d %T), '')";)
                echo "GPIO 24 Turned On"
        else
                echo "0" > /sys/class/gpio/gpio24/value
                $(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword sensor -e "INSERT INTO sensor values('7', 'LED', '', $(date + %Y-%m-%d %T))";)
                echo "GPIO 24 Turned Off"
        fi
else
        echo "in" > /sys/class/gpio/gpio24/direction
fi
if [ "$direction25" == "out" ]; then
        echo "out" > /sys/class/gpio/gpio25/direction
    if [ "$status25" == "1" ]; then
                echo "1" > /sys/class/gpio/gpio25/value
                $(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword sensor -e "INSERT INTO sensor values('8', 'LED', $(date + %Y-%m-%d %T), '')";)
                echo "GPIO 25 Turned On"
        else
                echo "0" > /sys/class/gpio/gpio25/value
                $(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword sensor -e "INSERT INTO sensor values('8', 'LED', '', $(date + %Y-%m-%d %T))";)
                echo "GPIO 25 Turned Off"
        fi
else
        echo "in" > /sys/class/gpio/gpio25/direction
fi
#Complete Loop
sleep $waitTime
done
This is my sensor mySQL database in phpMyAdmin:
Code:
CREATE TABLE IF NOT EXISTS `sensor` (
  `id` int(11) NOT NULL,
  `sensor` text NOT NULL,
  `switchOnLog` datetime NOT NULL,
  `switchOffLog` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
This is error message I get when I executing my GPIOServer.sh:
./GPIOServer.sh: 45: [: out: unexpected operator
./GPIOServer.sh: 59: [: out: unexpected operator
./GPIOServer.sh: 73: [: out: unexpected operator
./GPIOServer.sh: 87: [: out: unexpected operator
./GPIOServer.sh: 101: [: out: unexpected operator
./GPIOServer.sh: 115: [: out: unexpected operator
./GPIOServer.sh: 129: [: out: unexpected operator
./GPIOServer.sh: 143: [: out: unexpected operator

Hope you guys could help me out as soon as possible, thanks in advance, guys.
 
Old 07-17-2014, 06:47 PM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 5,388

Rep: Reputation: 408Reputation: 408Reputation: 408Reputation: 408Reputation: 408
Did you try a single = like
Code:
if [ "$direction4" = "out" ]; then...

Last edited by keefaz; 07-17-2014 at 06:50 PM.
 
Old 07-17-2014, 08:50 PM   #3
aoiregion
LQ Newbie
 
Registered: Jul 2014
Posts: 11

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by keefaz View Post
Did you try a single = like
Code:
if [ "$direction4" = "out" ]; then...
Thanks a lot keefaz, I have tried your method and now lesser error but still have a few.
This is my new edited code:
Code:
#!/bin/sh

mysqlusername="gpio"
mysqlpassword="kang"
mysqlname="sensor"
mysqlpass="kang"

#Set  Refresh
echo "How long do you want the wait time to be?"
read waitTime

#Invoke GPIO
echo "4" > /sys/class/gpio/export
echo "17" > /sys/class/gpio/export
echo "18" > /sys/class/gpio/export
echo "21" > /sys/class/gpio/export
echo "22" > /sys/class/gpio/export
echo "23" > /sys/class/gpio/export
echo "24" > /sys/class/gpio/export
echo "25" > /sys/class/gpio/export

#Start Loop
while :
do
#Read MySQL Data
#Direction
direction4=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinDirection FROM pinDirection WHERE pinNumber='4'";)
direction17=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinDirection FROM pinDirection WHERE pinNumber='17'";)
direction18=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinDirection FROM pinDirection WHERE pinNumber='18'";)
direction21=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinDirection FROM pinDirection WHERE pinNumber='21'";)
direction22=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinDirection FROM pinDirection WHERE pinNumber='22'";)
direction23=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinDirection FROM pinDirection WHERE pinNumber='23'";)
direction24=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinDirection FROM pinDirection WHERE pinNumber='24'";)
direction25=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinDirection FROM pinDirection WHERE pinNumber='25'";)
#Status
status4=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinStatus FROM pinStatus WHERE pinNumber='4'";)
status17=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinStatus FROM pinStatus WHERE pinNumber='17'";)
status18=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinStatus FROM pinStatus WHERE pinNumber='18'";)
status21=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinStatus FROM pinStatus WHERE pinNumber='21'";)
status22=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinStatus FROM pinStatus WHERE pinNumber='22'";)
status23=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinStatus FROM pinStatus WHERE pinNumber='23'";)
status24=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinStatus FROM pinStatus WHERE pinNumber='24'";)
status25=$(mysql -B --disable-column-names --user=$mysqlusername --password=$mysqlpassword gpio -e "SELECT pinStatus FROM pinStatus WHERE pinNumber='25'";)


#Run Commands
if [ "$direction4" = "out" ]; then
    echo "out" > /sys/class/gpio/gpio4/direction
    if [ "$status4" = "1" ]; then
        echo "1" > /sys/class/gpio/gpio4/value
        $(mysql --user=$mysqlname --password=$mysqlpass sensor -e "INSERT INTO sensor(id, sensor, switchOnLog, switchOffLog) values('1', 'Red LED', $(date +%Y-%m-%d.%H:%M:%S), '')";)
        echo "GPIO 4 Turned On"
    else
        echo "0" > /sys/class/gpio/gpio4/value
        $(mysql --user=$mysqlname --password=$mysqlpass sensor -e "INSERT INTO sensor(id, sensor, switchOnLog, switchOffLog) values('1', 'Red LED', '', $(date +%Y-%m-%d.%H:%M:%S))";)
        echo "GPIO 4 Turned Off"
    fi
else
    echo "in" > /sys/class/gpio/gpio4/direction
fi
if [ "$direction17" = "out" ]; then
        echo "out" > /sys/class/gpio/gpio17/direction
    if [ "$status17" = "1" ]; then
                echo "1" > /sys/class/gpio/gpio17/value
                $(mysql -B --user=$mysqlname --password=$mysqlpass sensor -e "INSERT INTO sensor values('2', 'Blue LED', $(date +%Y-%m-%d.%H:%M:%S), '')";)
                echo "GPIO 17 Turned On"
        else
                echo "0" > /sys/class/gpio/gpio17/value
                $(mysql -B --user=$mysqlname --password=$mysqlpass sensor -e "INSERT INTO sensor values('2', 'Blue LED', '', $(date +%Y-%m-%d.%H:%M:%S))";)
                echo "GPIO 17 Turned Off"
        fi
else
        echo "in" > /sys/class/gpio/gpio17/direction
fi
if [ "$direction18" = "out" ]; then
        echo "out" > /sys/class/gpio/gpio18/direction
    if [ "$status18" = "1" ]; then
                echo "1" > /sys/class/gpio/gpio18/value
                $(mysql --user=$mysqlname --password=$mysqlpass sensor -e "INSERT INTO sensor values('3', 'Green LED', $(date +%Y-%m-%d.%H:%M:%S), '')";)
                echo "GPIO 18 Turned On"
        else
                echo "0" > /sys/class/gpio/gpio18/value
                $(mysql --user=$mysqlname --password=$mysqlpass sensor -e "INSERT INTO sensor values('3', 'Green LED', '', $(date +%Y-%m-%d.%H:%M:%S))";)
                echo "GPIO 18 Turned Off"
        fi
else
        echo "in" > /sys/class/gpio/gpio18/direction
fi
if [ "$direction21" = "out" ]; then
        echo "out" > /sys/class/gpio/gpio21/direction
    if [ "$status21" = "1" ]; then
                echo "1" > /sys/class/gpio/gpio21/value
                $(mysql --user=$mysqlname --password=$mysqlpass sensor -e "INSERT INTO sensor values('4', 'Yellow LED', $(date +%Y-%m-%d.%H:%M:%S), '')";)
                echo "GPIO 21 Turned On"
        else
                echo "0" > /sys/class/gpio/gpio21/value
                $(mysql --user=$mysqlname --password=$mysqlpass sensor -e "INSERT INTO sensor values('4', 'Yellow LED', '', $(date +%Y-%m-%d.%H:%M:%S))";)
                echo "GPIO 21 Turned Off"
        fi
else
        echo "in" > /sys/class/gpio/gpio21/direction
fi
if [ "$direction22" = "out" ]; then
        echo "out" > /sys/class/gpio/gpio22/direction
    if [ "$status22" = "1" ]; then
                echo "1" > /sys/class/gpio/gpio22/value
                $(mysql --user=$mysqlusername --password=$mysqlpass sensor -e "INSERT INTO sensor values('5', 'LED', $(date +%Y-%m-%d.%H:%M:%S), '')";)
                echo "GPIO 22 Turned On"
        else
                echo "0" > /sys/class/gpio/gpio22/value
                $(mysql --user=$mysqlusername --password=$mysqlpass sensor -e "INSERT INTO sensor values('5', 'LED', '', $(date +%Y-%m-%d.%H:%M:%S))";)
                echo "GPIO 22 Turned Off"
        fi
else
        echo "in" > /sys/class/gpio/gpio22/direction
fi
if [ "$direction23" = "out" ]; then
        echo "out" > /sys/class/gpio/gpio23/direction
    if [ "$status23" = "1" ]; then
                echo "1" > /sys/class/gpio/gpio23/value
                $(mysql --user=$mysqlusername --password=$mysqlpass sensor -e "INSERT INTO sensor values('6', 'LED', $(date +%Y-%m-%d.%H:%M:%S), '')";)
                echo "GPIO 23 Turned On"
        else
                echo "0" > /sys/class/gpio/gpio23/value
                $(mysql --user=$mysqlusername --password=$mysqlpass sensor -e "INSERT INTO sensor values('6', 'LED', '', $(date +%Y-%m-%d.%H:%M:%S))";)
                echo "GPIO 23 Turned Off"
        fi
else
        echo "in" > /sys/class/gpio/gpio23/direction
fi
if [ "$direction24" = "out" ]; then
        echo "out" > /sys/class/gpio/gpio24/direction
    if [ "$status24" = "1" ]; then
                echo "1" > /sys/class/gpio/gpio24/value
                $(mysql --user=$mysqlusername --password=$mysqlpass sensor -e "INSERT INTO sensor values('7', 'LED', $(date +%Y-%m-%d.%H:%M:%S), '')";)
                echo "GPIO 24 Turned On"
        else
                echo "0" > /sys/class/gpio/gpio24/value
                $(mysql --user=$mysqlusername --password=$mysqlpass sensor -e "INSERT INTO sensor values('7', 'LED', '', $(date +%Y-%m-%d.%H:%M:%S))";)
                echo "GPIO 24 Turned Off"
        fi
else
        echo "in" > /sys/class/gpio/gpio24/direction
fi
if [ "$direction25" = "out" ]; then
        echo "out" > /sys/class/gpio/gpio25/direction
    if [ "$status25" = "1" ]; then
                echo "1" > /sys/class/gpio/gpio25/value
                $(mysql --user=$mysqlusername --password=$mysqlpass sensor -e "INSERT INTO sensor values('8', 'LED', $(date +%Y-%m-%d.%H:%M:%S), '')";)
                echo "GPIO 25 Turned On"
        else
                echo "0" > /sys/class/gpio/gpio25/value
                $(mysql --user=$mysqlusername --password=$mysqlpass sensor -e "INSERT INTO sensor values('8', 'LED', '', $(date +%Y-%m-%d.%H:%M:%S))";)
                echo "GPIO 25 Turned Off"
        fi
else
        echo "in" > /sys/class/gpio/gpio25/direction
fi
#Complete Loop
sleep $waitTime
done
This is new error message I get when I executing my GPIOServer.sh:
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the corresponds to your MYSQL server version for the right syntax to use near ':39:32)' at line 1 GPIO 4 Turned Off
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the corresponds to your MYSQL server version for the right syntax to use near ':39:32)' at line 1 GPIO 17 Turned Off
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the corresponds to your MYSQL server version for the right syntax to use near ':39:33)' at line 1 GPIO 18 Turned Off
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the corresponds to your MYSQL server version for the right syntax to use near ':39:33)' at line 1 GPIO 21 Turned Off
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the corresponds to your MYSQL server version for the right syntax to use near ':39:33)' at line 1 GPIO 22 Turned Off
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the corresponds to your MYSQL server version for the right syntax to use near ':39:33)' at line 1 GPIO 23 Turned Off
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the corresponds to your MYSQL server version for the right syntax to use near ':39:33)' at line 1 GPIO 24 Turned Off
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the corresponds to your MYSQL server version for the right syntax to use near ':39:32)' at line 1 GPIO 25 Turned Off

Hope you guys could help me out with it as soon as possible, thanks in advance, guys
 
Old 07-17-2014, 09:10 PM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,702

Rep: Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270Reputation: 1270
I believe your "$(date ...)" string needs quoting.

You might try '$(date...)'. IF that causes an error, try \'$(date...)\'.

Getting nested quotes right is tricky...

As an alternative, you might consider using Perl or python, with the DBI. You would then be able to open the database only once, and then do everything within a single session/transaction instead what looks like 23.

Last edited by jpollard; 07-17-2014 at 09:15 PM.
 
Old 07-18-2014, 04:18 AM   #5
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 5,388

Rep: Reputation: 408Reputation: 408Reputation: 408Reputation: 408Reputation: 408
Yes date inserts need quotes (string)
You can also use MySQL DATE_FORMAT
Code:
INSERT INTO sensor(id, sensor, switchOnLog, switchOffLog) values('1', 'Red LED', '', DATE_FORMAT('%Y-%m-%d.%T'))
Maybe easier to quote

Last edited by keefaz; 07-18-2014 at 04:19 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL insert database problem macaronij Linux - Server 3 07-22-2010 03:38 AM
phpmyadmin shows blank page; no "phpmyadmin" database in mysql qajaq Linux - Software 2 12-20-2009 12:23 PM
Copy MySQL database with PHPMyAdmin....how?!?!? vous Linux - Software 1 09-08-2009 11:18 AM
fixing mysql database table without phpmyadmin c0c0deuz Linux - Server 3 12-01-2007 08:17 PM
After insert data, Database is empty ivankong Linux - Software 2 06-16-2003 07:35 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration