GET request to upload data in database gives me 302 error

Website URL

https://stats3.rf.gd/

Error Message

+HTTPACTION:0,302,0

Other Information

I am actually trying to send sensors data to mysql database created for the website using GET request and php code.
kindly help me out…
this is my url to perform get method:
http://stats3.rf.gd/htdocs/d.php?C=49.80&F=121.65&x=1.10&y=1.07&z=-0.60&a=12.93&b=80.14&t=21:12:42_03-01-2024

Please note that we provide hosting intended for use of websites. Using our hosting as an IoT data aggregation platform is not supported:

Also, I’m not sure what this “302 error” means. With some difficulty I was able to find some search results related to Arduino, but not this error code, and I don’t know enough about Arduino programming to tell you what server behavior would cause your board to generate this error.

9 Likes

First of all, thank you for the quick reply and my query is…
I just want to upload data to the mysql database via HTTP GET request by simply using URL, consisting of path to the location of the php file and values, which then connects to the database and loads the values correspondingly . Here is my php code and url used…
http://stats3.rf.gd/htdocs/d.php?C=49.80&F=121.65&x=1.10&y=1.07&z=-0.60&a=12.93&b=80.14&t=21:12:42_03-01-2024

<?php
require 'config.php';
$temp_C = $_GET['C'];
$temp_F = $_GET['F'];
$x_axis = $_GET['x'];
$y_axis = $_GET['y'];
$z_axis = $_GET['z'];
$lat = $_GET['a'];
$lng = $_GET['b'];
$time_date = $_GET['t'];
echo $temp_C;
echo "<br>";
echo $temp_F;
echo "<br>";
echo $x_axis;
echo "<br>";
echo $y_axis;

echo "<br>";
echo $z_axis;
echo "<br>";
echo $lat;
echo "<br>";
echo $lng;
echo "<br>";
echo $time_date;
echo "<br";
$sql = "INSERT INTO data(temp_C,temp_F,x_axis,y_axis,z_axis,lat,long,time_date)
VALUES('".$temp_C."','".$temp_F."','".$x_axis."','".$y_axis."','".$z_axis."','".$lat."','".$lng."','".$time_date."')";
if($db->query($sql) === FALSE)
{ echo "Error: " . $sql . "<br>" . $db->error; }
echo "<br>";
echo $db->insert_id;

is it not possible to do like this? and I am not sure about the path to the php file correct… could you please tell me how to locate the files which are in the file manager from the website url…?
then, could you please share the ways to upload data to the database?

Regarding 302 error: When I try to upload data to the database created using HTTP GET method, it gives httpaction as 0:302:0 and I browsed about this in google. It is mentioned as follows:
What is an HTTP 302? The 302 status code is a redirection message that occurs when a resource or page you’re attempting to load has been temporarily moved to a different location . It’s usually caused by the web server and doesn’t impact the user experience, as the redirect happens automatically.

Thanks for your time and consideration.

Could you post your code formatted by using three backticks (the ` symbol) at the beginning and end of your code, so formatted like this?

your code here

This in particular seems wrong to me:

6 Likes

Sure.


require 'config.php';

$temp_C = $_GET['C'];

$temp_F = $_GET['F'];

$x_axis = $_GET['x'];

$y_axis = $_GET['y'];

$z_axis = $_GET['z'];

$lat = $_GET['a'];

$lng = $_GET['b'];

$time_date = $_GET['t'];

echo $temp_C;

echo "<br>";

echo $temp_F;

echo "<br>";

echo $x_axis;

echo "<br>";

echo $y_axis;

echo "<br>";

echo $z_axis;

echo "<br>";

echo $lat;

echo "<br>";

echo $lng;

echo "<br>";

echo $time_date;

echo "<br";

$sql = "INSERT INTO data(temp_C,temp_F,x_axis,y_axis,z_axis,lat,long,time_date)

VALUES('".$temp_C."','".$temp_F."','".$x_axis."','".$y_axis."','".$z_axis."','".$lat."','".$lng."','".$time_date."')";

if($db->query($sql) === FALSE)

{ echo "Error: " . $sql . "<br>" . $db->error; }

echo "<br>";

echo $db->insert_id;```

/htdocs should not be a part of the URL. htdocs is the root folder for the domain.

Missing >

first, you don’t need '"., it’s pointless. Just put the variable.

Second, that code is not secure, and anyone on the internet can modify the URL to make changes to your database (Including adding potentially malicious code, deleting everything, etc.) Learn More

This is also vulnerable

Don’t know where you see that. Your first URL (With the “htdocs”) returns a 404, and the correct URL (Without the “htdocs”) returns a 500 - I don’t see a 302 anywhere.

6 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.