I have already setup the blocks in App Inventor to submit data, because previously I did and it worked, however when retrieving data it worked too, except when I realized I have fetched all the data in the table and passed it into TinyDB
, then from TinyDB
, I compare the texts string that matches the user input.
Yes that allowed me to create a login page, but i was comparing data through App Inventor and not from MySQL. So what I did was I tried sending the strings from App Inventor into the php file, then supposedly it will query which will send out user id, username and password, where the username and password will be matched with the $_GET request from App Inventor(user).
Then the final result would be, the queried data would be then sent to App Inventor either as a row of string, and then I can use TinyDB
to store the user id, so that on the next page, i can call the id, then query the user data according to my apps needs.
Here's the code
//Details in asterisk to hide.
<?php
define('DB_SERVER', '******');
define('DB_USERNAME', '*******');
define('DB_PASSWORD', '*******');
define('DB_DATABASE', '*******');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
$query = "SELECT user_id, username, user_password FROM User_Login WHERE username='$username' AND user_password='$password'",
$username = mysqli_real_escape_string($db,$_GET['username']),
$password = mysqli_real_escape_string($db,$_GET['password']);
// Perform Query
$result = mysqli_query($db,$query);
// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
$message = 'Invalid query: ' . mysqli_error($db) . "
";
$message .= 'Whole query: ' . $query;
die($message);
}
// Use result
// Attempting to print $result won't allow access to information in the resource
// One of the mysql result functions must be used
while ($row = mysqli_fetch_assoc($result)) {
echo $row['$username'];
echo $row['username'];
echo $row['user_password'];
}
// Free the resources associated with the result set
// This is done automatically at the end of the script
mysqli_free_result($result);
?>