Sending data to database from ftp

Hi,

Thanks for reading my post, im new here and new to server/web development.

I am trying to get my SIM900 module to send data it collects to a SQL database i have here. I can sucessfully get it to connect to the FTP server and create a .txt file with the data in it (yay, progress), which i would then like to put into the database, but am not sure how to do this.

Alternatively i understand i should be able send a http command with the data in it (something like mywebsite.com/htdocs/enterdata.php?data1=1,data2=5.23,data3=734587) to a .php script which will put the data into the database. i have a php script in the /htdocs folder but when i try send it data i get redirected to 404 page not found. i dont have any website set up just the php script and the data i have managed to send in txt files.
I see that this method may not work as infinityfree checks for java and cookies which my module does not have, but i hope the ftp to database method might be plausible.

Any help or direction is much appreciated.

C

Hi and happy developing :grin:

Can i have your site url and the file you’re trying to configure? it’ll make our work easier.

correct is:

enterdata.php?data1=1&data2=5.23&data3=734587

make sure the target page be page.php not htdoces/page.php

1 Like

Can you remove the htdocs part from the URL and see if that helps? The htdocs folder is the folder that the domain name is linked to. So a file at the location htdocs/enterdata.php can be access as http://example.com/enterdata.php. You don’t need to specify the document root in the URL.

1 Like

Cheers for you help, My site is “cul8gfc1.epizy.com” or “nordickindustries.epizy.com
Here is my php script

<?php

    // Prepare variables for database connection
   
    $dbusername = "epiz_24743320";  // enter database username, I used "arduino" in step 2.2
    $dbpassword = "password";  // enter database password, I used "arduinotest" in step 2.2
    $server = "sql110.epizy.com"; // IMPORTANT: if you are using XAMPP enter "localhost", but if you have an online website enter its address, ie."www.yourwebsite.com"

    // Connect to your database

    $dbconnect = mysql_pconnect($server, $dbusername, $dbpassword);
    $dbselect = mysql_select_db("epiz_24743320_testData",$dbconnect);

    // Prepare the SQL statement

    $sql = "INSERT INTO simData (moduleID) VALUES ('".$_GET["moduleID"]."')";
    $sql = "INSERT INTO simData (sen1) VALUES ('".$_GET["sen1"]."')";
    $sql = "INSERT INTO simData (sen2) VALUES ('".$_GET["sen2"]."')";    
    $sql = "INSERT INTO simData (sen3) VALUES ('".$_GET["sen3"]."')";
    $sql = "INSERT INTO simData (sen4) VALUES ('".$_GET["sen4"]."')";
    $sql = "INSERT INTO simData (sen5) VALUES ('".$_GET["sen5"]."')";
    $sql = "INSERT INTO simData (sen6) VALUES ('".$_GET["sen6"]."')";
    $sql = "INSERT INTO simData (sen7) VALUES ('".$_GET["sen7"]."')";
    $sql = "INSERT INTO simData (sen8) VALUES ('".$_GET["sen8"]."')";
    $sql = "INSERT INTO simData (sen9) VALUES ('".$_GET["sen9"]."')";
    $sql = "INSERT INTO simData (sen10) VALUES ('".$_GET["sen10"]."')";
    $sql = "INSERT INTO simData (sen11) VALUES ('".$_GET["sen11"]."')";
    $sql = "INSERT INTO simData (sen12) VALUES ('".$_GET["sen12"]."')";
    $sql = "INSERT INTO simData (sen13) VALUES ('".$_GET["sen13"]."')";
    $sql = "INSERT INTO simData (sen14) VALUES ('".$_GET["sen14"]."')";
    $sql = "INSERT INTO simData (sen15) VALUES ('".$_GET["sen15"]."')";
    $sql = "INSERT INTO simData (sen16) VALUES ('".$_GET["sen16"]."')";



    // Execute SQL statement

    mysql_query($sql);

?>

When i try at the moment to send data through browser using

http://cul8gfc1.epizy.com/send_data.php?moduleID=0023&sen1=0.55&sen2=2.84

i get redirected to “http://suspendeddomain.org/b/

indent preformatted text by 4 spaces
`<?php

// Prepare variables for database connection

$dbusername = "epiz_24743320";  // enter database username, 
$dbpassword = "password";  // enter database password
$server = "sql110.epizy.com"; // IMPORTANT: if you are using XAMPP enter "localhost"

// Connect to your database

$dbconnect = mysql_pconnect($server, $dbusername, $dbpassword);
$dbselect = mysql_select_db("epiz_24743320_testData",$dbconnect);

// Prepare the SQL statement

$sql = "INSERT INTO simData (moduleID) VALUES ('".$_GET["moduleID"]."')";
$sql = "INSERT INTO simData (sen1) VALUES ('".$_GET["sen1"]."')";
$sql = "INSERT INTO simData (sen2) VALUES ('".$_GET["sen2"]."')";    
$sql = "INSERT INTO simData (sen3) VALUES ('".$_GET["sen3"]."')";
$sql = "INSERT INTO simData (sen4) VALUES ('".$_GET["sen4"]."')";
$sql = "INSERT INTO simData (sen5) VALUES ('".$_GET["sen5"]."')";
$sql = "INSERT INTO simData (sen6) VALUES ('".$_GET["sen6"]."')";
$sql = "INSERT INTO simData (sen7) VALUES ('".$_GET["sen7"]."')";
$sql = "INSERT INTO simData (sen8) VALUES ('".$_GET["sen8"]."')";
$sql = "INSERT INTO simData (sen9) VALUES ('".$_GET["sen9"]."')";
$sql = "INSERT INTO simData (sen10) VALUES ('".$_GET["sen10"]."')";
$sql = "INSERT INTO simData (sen11) VALUES ('".$_GET["sen11"]."')";
$sql = "INSERT INTO simData (sen12) VALUES ('".$_GET["sen12"]."')";
$sql = "INSERT INTO simData (sen13) VALUES ('".$_GET["sen13"]."')";
$sql = "INSERT INTO simData (sen14) VALUES ('".$_GET["sen14"]."')";
$sql = "INSERT INTO simData (sen15) VALUES ('".$_GET["sen15"]."')";
$sql = "INSERT INTO simData (sen16) VALUES ('".$_GET["sen16"]."')";



// Execute SQL statement

mysql_query($sql);

?>
`

Semi Success!
http://nordickindustries.epizy.com/send_data.php?moduleID=0023&sen1=2.458&sen2=347&sen3=0.1634
this added blank rows to my database which has not happened at all yet. I guess my php needs some tweaking to get the correct values out?

Hi,

Here is the working version of my PHP script which successfully uploads data from the url to my database. Yet to try with my SIM900 module but i’m hopeful and will update the thread with my results. This exercise has given me lots more knowledge of PHP and server setup so thats good. Its worth noting that i must provide a value for each of the 16 “senX” values and the moduleid value or else i get an error. I will try fix this most likely.
Cheers
C

<html>

<body>

<?php

$moduleid = 0;

$sen1 = 0;

$sen2 = 0;

$sen3 = 0;

$sen4 = 0;

$sen5 = 0;

$sen6 = 0;

$sen7 = 0;

$sen8 = 0;

$sen9 = 0;

$sen10 = 0;

$sen11 = 0;

$sen12 = 0;

$sen13 = 0;

$sen14 = 0;

$sen15 = 0;

$sen16 = 0;

print_r($_GET);

echo "<br>";

if($_GET["a"] === "") echo "a is an empty string"."<br>";

if($_GET["a"] === false) echo "a is false"."<br>";

if($_GET["a"] === null) echo "a is null"."<br>";

if(isset($_GET["a"])) echo "a is set"."<br>";

if(!empty($_GET["a"])) echo "a is not empty"."<br>";

$moduleid = $_GET["moduleid"];

$sen1 = $_GET["sen1"];

$sen2 = $_GET["sen2"];

$sen3 = $_GET["sen3"];

$sen4 = $_GET["sen4"];

$sen5 = $_GET["sen5"];

$sen6 = $_GET["sen6"];

$sen7 = $_GET["sen7"];

$sen8 = $_GET["sen8"];

$sen9 = $_GET["sen9"];

$sen10 = $_GET["sen10"];

$sen11 = $_GET["sen11"];

$sen12 = $_GET["sen12"];

$sen13 = $_GET["sen13"];

$sen14 = $_GET["sen14"];

$sen15 = $_GET["sen15"];

$sen16 = $_GET["sen16"];

$con = mysql_connect("sql110.epizy.com","epiz_24743320","password");

if (!$con)

{

die('Could not connect: ' . mysql_error());

}

mysql_select_db("epiz_24743320_testData", $con);

$sql="INSERT INTO simData (moduleID, sen1, sen2, sen3, sen4, sen5, sen6, sen7, sen8, sen9, sen10, sen11, sen12, sen13, sen14, sen15, sen16) VALUES ($moduleid, $sen1, $sen2, $sen3, $sen4, $sen5, $sen6, $sen7, $sen8, $sen9, $sen10, $sen11, $sen12, $sen13, $sen14, $sen15, $sen16)";

//$sql="INSERT INTO simData (moduleID, sen1) VALUES ($moduleid, $sen1)";

if (!mysql_query($sql,$con))

{

die('Error: test' . mysql_error());

}

echo "1 record added";

mysql_close($con)

?>

</body>

</html>