Hello,
I am creating an app that finds a piece of username data after a click of a button.
So far I have:
>>Installed and configured xampp
>>Portforwarded my router
>>set up an online webserver
>>Used PHP to create a database and implement it into the webserver.
Php code index.php
I ran my public webpage and I know for sure the php code works and adds the data to the webserver. I am not sure how to make android studio grab the database information from the public website.
(https//PUBLICIPADRESS:8080)
Any links or tutorials on how to do this would be appreciated, Thanks!
- Denver
I am creating an app that finds a piece of username data after a click of a button.
So far I have:
>>Installed and configured xampp
>>Portforwarded my router
>>set up an online webserver
>>Used PHP to create a database and implement it into the webserver.
Php code index.php
Code:
<?php
echo "<h1>Hello World</h1>";
$servername = "localhost";
$username = "root";
$password = "";
$db = "testDatabase";
$table = "myGuests";
$conn = new mysqli($servername, $username, $password);
if ($conn->connect_error) {
die("Connection failed: <br>" . $conn->connect_error);
}
else {
echo "Connected to MySQL successfully <br>";
}
$sql = "CREATE DATABASE $db";
if ($conn->query($sql) === TRUE) {
echo "Database created successfully<br>";
} else {
echo "Error creating database: <br>" . $conn->error;
}
$conn = new mysqli($servername, $username, $password, $db);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "CREATE TABLE $table (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
usernameOut VARCHAR(50) NOT NULL,
passwordOut VARCHAR(50) NOT NULL,
reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)";
if ($conn->query($sql) === TRUE) {
echo "Table MyGuests created successfully<br>";
} else {
echo "Error creating table: <br>" . $conn->error;
}
$sql = "INSERT INTO $table (usernameOut, passwordOut)
VALUES ('Admin', '1-password')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully<br>";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$sql = "SELECT id, usernameOut, passwordOut FROM MyGuests";
$result = $conn->query($sql); // $result will be an array
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
}
} else {
echo "0 results";
}
$sql = 'DROP DATABASE testDatabase';
if ($conn->query($sql) === TRUE) {
echo "Database deleted successfully<br>";
} else {
echo "Error deleting database:<br> " . $conn->error;
}
$conn->close();
echo "The time is " . date("h:i:sa");
?>
I ran my public webpage and I know for sure the php code works and adds the data to the webserver. I am not sure how to make android studio grab the database information from the public website.
(https//PUBLICIPADRESS:8080)
Any links or tutorials on how to do this would be appreciated, Thanks!
- Denver