Question
I was wondering if someone could tell me what was up with my PHP script So here is my PHP script. I'm trying to parse
I was wondering if someone could tell me what was up with my PHP script
So here is my PHP script. I'm trying to parse JSON objects sent from my friend and then display them on my LAMP Server page.
PHP CODE:
$data = json_decode(file_get_contents('php://input'));
$device = $data->{"tempC"};
$con = mysqli_connect('127.0.0.1','root','root','DeviceDB') or die("e$
$query = "INSERT INTO Temperature (temp, device_id) VALUES (" . $device . "," $
mysqli_query($con, $query) or die("error");
?>
Here is the "nodejsscript.js" that I am using the make the proccess easier. IT allows me to confirm whether or not I recieved the objects or not.
Node Code:
var request = require('request');
for(var i=0;i<20; i++){
data = { deviceID: "Dummy", tempC: Math.floor(Math.random()*(100 -1)+1), tempF: Math.floor(Math.random()*(100 -1)+1), photoCell: Math.floor(Math.random()*(100 -1)+1), proxSensor: Math.floor(Math.random()*(100 -1)+1), timeStamp: Math.floor(Math.random()*(100 -1)+1) }; //console.log(data); postToMongo(data); } data = { deviceID: "Dummy", tempC: Math.floor(Math.random()*(100 -1)+1), tempF: Math.floor(Math.random()*(100 -1)+1), photoCell: Math.floor(Math.random()*(100 -1)+1), proxSensor: Math.floor(Math.random()*(100 -1)+1), timeStamp: Math.floor(Math.random()*(100 -1)+1) }; //console.log(data); postToMongo(data);
function postToMongo(data) { //Make the post request({ method: 'POST', url: '127.0.0.1/Dontchange.php', body: data, json: true }, function(err, rsp, body) { if (err || rsp.statusCode != 200) { console.log('HTTP error:', err, rsp.statusCode, body); } else { console.log(`Success! ${body}`); } }); }
I keep receiving an error like this:
Node Error:
HTTP error: null 404
Not Found
The requested URL /Dontchange.php was not found on this server.
Apache/2.4.18 (Ubuntu) Server at 127.0.0.1 Port 80
Also, here is an error when I run th php script that parses the JSON Objects called "Dontchange.php"
PHP ERROR:
PHP Parse error: syntax error, unexpected 'INSERT' (T_STRING), expecting ')' in /home/chris/Desktop/Dontchange.php on line 9
But, I'm not sure what the error actually is.
I was hoping somewhere here could point me in the correct direction for answers.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started