On 10/09/2020 22:36, A. Dumas wrote:
> Op 10-9-2020 21:38, NY wrote:
>> Yes I'd already identified that cron would be a good way of triggering
>> the upload. It's a matter of working out what can be run (via cron) at
>> the Pi which makes a remote web server add data to an SQL database
>> held on its server, preferably searching for each row of data that is
>> about
>
> The normal solution for simple webhosting with no outside facing
> database, is: make a PHP script on the web server that receives your
> data, maybe via a form upload, maybe directly as a query parameter; that
> processes the data and connects to the database to save it. AKA build
> your own API. Make sure you add some sort of login and/or secret key
> and/or checksum. Also make sure that you sanitize your input before
> throwing it to the db, even if it is just you!
Amen to all of that.
Here is the core code for updating a very simple MySql database from a
form variables in php
$fields=array( "pressure","temperature",....);
// this defines all the variables you will send as form variables
$query = "insert into data set";
$flag=0;
foreach($fields as $name) //read variables and add to query
{
if($flag) $query .=',';
if(isset($_GET[$name]))
$query.= sprintf(" %s='%s'",$name,$_POST[$name]);
else
$query.= sprintf(" %s='%s'",$name,"");
$flag++;
}
;
// echo $query;
$link=mysqli_connect("localhost", "myuser","mypass","weather");
if($link)
{
mysqli_query($link, $query);
}
mysqli_close($link);
And as for cron,you need to use:
curl myweather.mydomain.com/upload.php?pressure=1005&temperature=37.5&.....
It really is that simple.
Of course there is no data validation done and not much security
there,but that you can add in later on once it actually works
--
The biggest threat to humanity comes from socialism, which has utterly
diverted our attention away from what really matters to our existential
survival, to indulging in navel gazing and faux moral investigations
into what the world ought to be, whilst we fail utterly to deal with
what it actually is.
--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)
|