HELP ME WITH BLOCKS(newbie here)

So i have here a code for a user profile the problem i really dont know what blocks should use to display the userdetails in my app, can someone help me demonstrate it? please

<?php session_start(); include('connect.php'); if(isset($_SESSION['username']) && isset($_SESSION['resident_id'])) { $resident_id = $_SESSION['resident_id']; $resident_query = "SELECT * FROM residents WHERE id = $resident_id"; $resident_result = $conn->query($resident_query); if ($resident_result->num_rows > 0) { $resident_row = $resident_result->fetch_assoc(); / echo "First Name: " . $resident_row['firstname'] . "
"; echo "Middle Name: " . $resident_row['middlename'] . "
"; echo "Last Name: " . $resident_row['lastname'] . "
"; echo "Gender: " . $resident_row['gender'] . "
"; echo "Birthplace: " . $resident_row['birthplace'] . "
"; // Calculate age based on birthdate $birthdate = new DateTime($resident_row['birthdate']); $currentDate = new DateTime(); $age = $birthdate->diff($currentDate)->y; echo "Age: " . $age . "
"; // Display civil status, purok, or any other fields you have echo "Civil Status: " . $resident_row['civil_status'] . "
"; echo "Purok: " . $resident_row['purok'] . "
"; } else { echo "No resident details found for this user."; } } else { header("Location: login.php"); exit(); } $conn->close(); ?>

You have a couple of errors in your php code. I have therefore edited it and formatted it to make it more readable.

<?php session_start();
include "connect.php";
if (isset($_SESSION["username"]) && isset($_SESSION["resident_id"])) {
    $resident_id = $_SESSION["resident_id"];
    $resident_query = "SELECT * FROM residents WHERE id = $resident_id";
    $resident_result = $conn->query($resident_query);
    if ($resident_result->num_rows > 0) {
        $resident_row = $resident_result->fetch_assoc();
        echo "First Name: " . $resident_row["firstname"] . "";
        echo "Middle Name: " . $resident_row["middlename"] . "";
        echo "Last Name: " . $resident_row["lastname"] . "";
        echo "Gender: " . $resident_row["gender"] . "";
        echo "Birthplace: " . $resident_row["birthplace"] . "";
        // Calculate age based on birthdate $birthdate = new DateTime($resident_row['birthdate']); $currentDate = new DateTime(); $age = $birthdate->diff($currentDate)->y; echo "Age: " . $age . "";
        // Display civil status, purok, or any other fields you have echo "Civil Status: " . $resident_row['civil_status'] . "";
        echo "Purok: " .  $resident_row["purok"] . "";
    } else {
        echo "No resident details found for this user.";
    }
} else {
    header("Location: login.php");
    exit();
}
$conn->close(); ?>

Perhaps this may make it work ?

You probably need to spend some time learning how to use AppInventor...

As before, as recommended to your other (now deleted) account, read this tutorial on connecting AppInventor with MySql/php

Any further questions, if you are having problems, should include your relevant AppInventor blocks and php scripts, and mysql data for review.

I also add your other info from your deleted account:

Here is a step-by-step process to implement the blocks for the provided PHP code:

Retrieve Data from TextBoxes:
    When the user clicks the registration button (ButtonRegister.Click), use the "TextBox.Text" blocks to retrieve the text entered by the user in each TextBox (TextBoxFirstname.Text, TextBoxMiddlename.Text, TextBoxLastname.Text, TextBoxUsername.Text, TextBoxPassword.Text).

Build URL:
    Use the "text" blocks to concatenate the retrieved values into a single string, forming the URL query parameters.
    Use the "join" block to concatenate these parameters into the complete URL string. This URL will point to your PHP script.

Make Web Request:
    Use the "Web1.PostText" block to send a POST request to the PHP script.
    In the "Web1.PostText" block, provide the constructed URL as the URL parameter.
    In the "Web1.PostText" block, provide the concatenated string of user data as the Text parameter.

Handle Response:
    Use the "Web1.GotText" event handler to handle the response from the PHP script.
    Inside this event handler, use an "if" block to check the response text for different scenarios (e.g., "User registered successfully", "You are already registered with a different username", "You are not registered as a resident").
    Based on the response, display an appropriate message to the user using the "Notifier" component.

Here is the exact step-by-step process:

Step 1: Retrieve Data from TextBoxes

Use the "TextBox.Text" blocks to retrieve the text entered by the user in each TextBox (TextBoxFirstname.Text, TextBoxMiddlename.Text, TextBoxLastname.Text, TextBoxUsername.Text, TextBoxPassword.Text).
Step 2: Build URL

Use the "text" blocks to concatenate the retrieved values into a single string, forming the URL query parameters.
Use the "join" block to concatenate these parameters into the complete URL string. This URL will point to your PHP script.
Step 3: Make Web Request

Use the "Web1.PostText" block to send a POST request to the PHP script.
Provide the constructed URL as the URL parameter.
Provide the concatenated string of user data as the Text parameter.
Step 4: Handle Response

Use the "Web1.GotText" event handler to handle the response from the PHP script.
Inside this event handler, use an "if" block to check the response text for different scenarios.
Based on the response, display an appropriate message to the user using the "Notifier" component.
1 Like