orchidsoftware / platform

Orchid is a @laravel package that allows for rapid application development of back-office applications, admin/user panels, and dashboards.
https://orchid.software
MIT License
4.38k stars 644 forks source link

How to dynamically auto fill input textbox fields with select option using php and mysql #2850

Open Timkats opened 2 months ago

Timkats commented 2 months ago

Hi Guys, iam working on project but iam currently faced with a challenge to implement OnChange event Javascript method in our code. I do have two tables; One is for user registration and the other is for stage registration. The scenario is that i must add a user to a stage for which the user id is automatically fetched from the user table and easily adds to the AddUserToStage form, which is working well. However, iam supposed to select the name of the stage from the drop down select option list which displays stage name fetched dynamically from the database table(StageRegistration). The requirement is that when i select a stage name i would like to have other additionally corresponding textfields automatically fetch and fill their corresponding data from the database table(StageRegistration). How do i do that? Any help is highly appreciated. Below is the sample code ian using;

Code Sample: <?php require_once('includes/connection.php'); require_once('includes/headerboda.php'); require_once('includes/navbarboda.php');

error_reporting(0); session_start();

// This is where you would do any database call

if(!empty($_POST)) {

$stagename = $_GET['stagename'];

$getname = "SELECT StageNumber,StgCreationDate,StageLocation,StageChair,StageChairContact,StageChairNIN,StageVillage,StageParish,StageDistrict FROM stageregistration
            WHERE StageName = '".$stagename."' ";
$query_run = mysqli_query($connection,$getname);
$row = mysqli_fetch_array($query_run);
// Send back a jSON array via echo
echo json_encode($row);
// Exit probably not required if you
// separate out your code into two pages
exit;

}

?>

Stage Members Dashboard

Add Member to Boda Stage Form

<?php require_once('includes/footerboda.php'); require_once('includes/scriptsboda.php'); ?>

Timkats commented 2 months ago

Hi Guys, iam working on a project form where by i would like to search for data from the mysql database using ID and then auto fill out the input textbox fields. Ihave tried to write up a code as seen below but failed to show corresponding data in the various form fields. Any Help is highly welcome. See code below:

HTML Form:

PHP CODE (getStage.php)

<?php require_once('includes/connection.php');

if(isset($_POST['search_post_btn'])) {

$id = $_POST['id'];
$sql = "SELECT * FROM stageregistration WHERE id = '$id' ";
$resultSet = mysqli_query($connection,$sql);
if($row > 0)
{
    while($row = mysqli_fetch_assoc($resultSet))
    {
        $data = $row;
    }
}
echo json_encode($data);

} ?>

JSON FILE