Difference between revisions of "AppInventor: Menyiapkan Server Apache dan MySQL"
Jump to navigation
Jump to search
Onnowpurbo (talk | contribs) |
Onnowpurbo (talk | contribs) |
||
Line 12: | Line 12: | ||
exit | exit | ||
+ | |||
+ | Edit /var/www/html/put_data.php | ||
+ | |||
+ | <?php | ||
+ | // Retrieve data from the POST request | ||
+ | $id = $_POST['id']; | ||
+ | $newName = $_POST['newName']; | ||
+ | $newEmail = $_POST['newEmail']; | ||
+ | |||
+ | // Database connection parameters | ||
+ | $servername = "your_mysql_server"; | ||
+ | $username = "your_mysql_username"; | ||
+ | $password = "your_mysql_password"; | ||
+ | $dbname = "your_database_name"; | ||
+ | |||
+ | // 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 your_table_name SET name='$newName', email='$newEmail' WHERE id=$id"; | ||
+ | |||
+ | if ($conn->query($sql) === TRUE) { | ||
+ | echo "Data updated successfully"; | ||
+ | } else { | ||
+ | echo "Error: " . $sql . "<br>" . $conn->error; | ||
+ | } | ||
+ | |||
+ | $conn->close(); | ||
+ | ?> | ||
==Pranala Menarik== | ==Pranala Menarik== |
Revision as of 19:23, 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
Edit /var/www/html/put_data.php
<?php // Retrieve data from the POST request $id = $_POST['id']; $newName = $_POST['newName']; $newEmail = $_POST['newEmail'];
// Database connection parameters $servername = "your_mysql_server"; $username = "your_mysql_username"; $password = "your_mysql_password"; $dbname = "your_database_name";
// 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 your_table_name SET name='$newName', email='$newEmail' WHERE id=$id"; if ($conn->query($sql) === TRUE) { echo "Data updated successfully"; } else { echo "Error: " . $sql . "
" . $conn->error; } $conn->close(); ?>