Difference between revisions of "AppInventor: Menyiapkan Server Apache dan MySQL"
Jump to navigation
Jump to search
Onnowpurbo (talk | contribs) |
Onnowpurbo (talk | contribs) |
||
Line 27: | Line 27: | ||
<?php | <?php | ||
// Retrieve data from the POST request | // Retrieve data from the POST request | ||
− | $ | + | $iotID = $_POST['iotID']; |
− | $ | + | $iottime = $_POST['iottime']; |
− | $ | + | $iotsensor = $_POST['iotsensor']; |
+ | $iotdata = $_POST['iotdata']; | ||
// Database connection parameters | // Database connection parameters | ||
− | $servername = " | + | $servername = "127.0.0.1"; |
− | $username = " | + | $username = "iot"; |
− | $password = " | + | $password = "iot"; |
− | $dbname = " | + | $dbname = "iot"; |
// Create connection | // Create connection | ||
Line 46: | Line 47: | ||
// Update data in the database | // Update data in the database | ||
− | $sql = "UPDATE | + | $sql = "UPDATE iot SET iottime='$iottime', iotsensor='$iotsensor', iotdata='$iotdata' WHERE iotid=$iotid"; |
if ($conn->query($sql) === TRUE) { | if ($conn->query($sql) === TRUE) { |
Latest revision as of 19:33, 14 January 2024
Instalasi
sudo su apt update apt install apache2 php php-common php-mysql libapache2-mod-php mariadb-server
mysql -u root -p123456 CREATE DATABASE iot; CREATE USER 'iot' IDENTIFIED BY 'iot'; GRANT ALL PRIVILEGES ON iot.* TO 'iot'; FLUSH PRIVILEGES; exit
mysql -u root -p123456 USE iot; CREATE TABLE iot ( iotID int, iottime varchar(100), iotsensor varchar(255), iotdata varchar(255) ); exit
Edit /var/www/html/put_data.php
<?php // Retrieve data from the POST request $iotID = $_POST['iotID']; $iottime = $_POST['iottime']; $iotsensor = $_POST['iotsensor']; $iotdata = $_POST['iotdata'];
// Database connection parameters $servername = "127.0.0.1"; $username = "iot"; $password = "iot"; $dbname = "iot";
// Create connection $conn = new mysqli($servername, $username, $password, $dbname);
// Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Update data in the database $sql = "UPDATE iot SET iottime='$iottime', iotsensor='$iotsensor', iotdata='$iotdata' WHERE iotid=$iotid"; if ($conn->query($sql) === TRUE) { echo "Data updated successfully"; } else { echo "Error: " . $sql . "
" . $conn->error; } $conn->close(); ?>