I am having troubles getting my php script to run via php in my LAMP server. Heres my code that I'm having issues with.
# Insert Statement
$insert ="INSERT INTO ACRC VALUES('','','1C3-4A','$fs','$acrc1c3_4afs');
INSERT INTO ACRC VALUES('','','1C3-4A','$fi','$acrc1c3_4afi');
INSERT INTO ACRC VALUES('','','1C3-4A','$fo','$acrc1c3_4afo');
INSERT INTO ACRC VALUES('','','1C3-4B','$fs','$acrc1c3_4bfs');
INSERT INTO ACRC VALUES('','','1C3-4B','$fi','$acrc1c3_4bfi');
INSERT INTO ACRC VALUES('','','1C3-4B','$fo','$acrc1c3_4bfo');
INSERT INTO ACRC VALUES('','','1C3-12A','$fs','$acrc1c3_12afs');
INSERT INTO ACRC VALUES('','','1C3-12A','$fi','$acrc1c3_12afi');
INSERT INTO ACRC VALUES('','','1C3-12A','$fo','$acrc1c3_12afo');
INSERT INTO ACRC VALUES('','','1C3-12B','$fs','$acrc1c3_12bfs');
INSERT INTO ACRC VALUES('','','1C3-12B','$fi','$acrc1c3_12bfi');
INSERT INTO ACRC VALUES('','','1C3-12B','$fo','$acrc1c3_12bfo');";
echo "$insert";
mysql_query($insert) or die(mysql_error());
echo "$insert";
?>
Running this command returns the following result.
[root@enseva html]# php snmp.php
ACRC Unit 1C3-4A : Fan Speed 73.3 % : Fluid In Temperature 47.2 F : Fluid Out Temperature 55 F
ACRC Unit 1C3-4B : Fan Speed 74 % : Fluid In Temperature 47.8 F : Fluid Out Temperature 53.5 F
ACRC Unit 1C3-12A : Fan Speed 28.9 % : Fluid In Temperature 44.7 F : Fluid Out Temperature 46.4 F
ACRC Unit 1C3-12B : Fan Speed 28.5 % : Fluid In Temperature 47.1 F : Fluid Out Temperature 62.9 F
INSERT INTO ACRC VALUES('','','1C3-4A','Fan Speed','73.3');
INSERT INTO ACRC VALUES('','','1C3-4A','Fluid Temperature In','47.2');
INSERT INTO ACRC VALUES('','','1C3-4A','Fluid Temperature Out','55');
INSERT INTO ACRC VALUES('','','1C3-4B','Fan Speed','74');
INSERT INTO ACRC VALUES('','','1C3-4B','Fluid Temperature In','47.8');
INSERT INTO ACRC VALUES('','','1C3-4B','Fluid Temperature Out','53.5');
INSERT INTO ACRC VALUES('','','1C3-12A','Fan Speed','28.9');
INSERT INTO ACRC VALUES('','','1C3-12A','Fluid Temperature In','44.7');
INSERT INTO ACRC VALUES('','','1C3-12A','Fluid Temperature Out','46.4');
INSERT INTO ACRC VALUES('','','1C3-12B','Fan Speed','28.5');
INSERT INTO ACRC VALUES('','','1C3-12B','Fluid Temperature In','47.1');
INSERT INTO ACRC VALUES('','','1C3-12B','Fluid Temperature Out','62.9');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 'INSERT INTO ACRC VALUES('','','1C3-4A','Fluid Temperature In','47.2');INSERT IN' at line 2
Now I've take then result from that and manually put it in my mysql and it worked as is although it did return 2 warning with each insert statement. The first value is an autoincrement id value and the second is a timestamp.
For a followup question my timestamp is returning all 0's.
Can you guys help with my question? I've been a long time lurker and this site has helped me much in the past.
You cannot send the "INSERT INTO"s like this. But you can do the following:
$insert = "INSERT INTO ACRC VALUES
('','','1C3-4A','$fs','$acrc1c3_4afs'),
('','','1C3-4A','$fi','$acrc1c3_4afi'),
('','','1C3-4A','$fo','$acrc1c3_4afo'),
('','','1C3-4B','$fs','$acrc1c3_4bfs'),
('','','1C3-4B','$fi','$acrc1c3_4bfi'),
('','','1C3-4B','$fo','$acrc1c3_4bfo'),
('','','1C3-12A','$fs','$acrc1c3_12afs'),
('','','1C3-12A','$fi','$acrc1c3_12afi'),
('','','1C3-12A','$fo','$acrc1c3_12afo'),
('','','1C3-12B','$fs','$acrc1c3_12bfs'),
('','','1C3-12B','$fi','$acrc1c3_12bfi'),
('','','1C3-12B','$fo','$acrc1c3_12bfo');";
As a reference: http://www.electrictoolbox.com/mysql-insert-multiple-records/