Jump to content

Populate Edit Form


SalientAnimal

Recommended Posts

Hi all,

 

I have a pretty basic front end system where specific details are displayed.

 

There is also and edit button next to each record that is displayed however not all info about this record is displayed.

When I click edit, I want a query to run on my next page, which will pre-populate the form with information from a query using the reference from the previous page.

 

A basic example is:

if(isset($_GET['entity_code']))
echo $entity_code;
$sql = "SELECT 
		id
		,	username
		,	region
		,	entity_code
		,	address_0
		,	address_1
		,	address_2
		,	address_3
		,	address_4
		,	contact_number_1
		,	contact_number_2
		FROM	
			scrm.entity_details
		WHERE entity_number= '$entity_number'";

if ($result = $mysqli->query($sql)) {
 
    /* fetch associative array */
    while ($row = $result->fetch_assoc()) {
        printf ("%s (%s)\n", $row['outlet_number'], $row['outlet_name']);
}
}
/* close connection */
$mysqli->close();

 

The entity number is passed successfully from the previous page, however my form is not populating and various I have tried give me a number of different outcomes.

 

The below is where I am trying to populate my form:

                <input type="hidden" class="form-control" value="<?php ECHO $_SESSION['username']; ?>" name="username" readonly>	

				<div class="form-group">
				    <label>Entity Number :</label>
                      <input type="text" class="form-control" value="<?php ECHO $row['entity_number']; ?>" name="outlet_number">
				</div>

				<div class="form-group">
				    <label>Entity Name :</label>
                      <input type="text" class="form-control" value="<?php ECHO $row['entity_name']; ?>" name="outlet_number">
				</div>				

I really don't know where I am going wrong...

 

Link to comment
Share on other sites

I've made some changes to this now and I have managed to get the entity code from the previous page to echo correctly. But what I can seem to get right is to now use this entity number that is passed to query my database and populate the form:

$link = mysqli_connect("localhost", "username", "password", "db");
if(isset($_GET['entity_number']))
{
$store_code = $_GET['entity_number'];}

echo $entity_number;
$sql = mysqli_query ($link,"SELECT 
		id
		,	username
		,	entity_number
		,	entity_name
		,	address_0
		,	address_1
		,	address_2
		,	address_3
		,	address_4
		,	contact_number_1
		,	contact_number_2

		FROM	
			scrm.liquor_licenses
		WHERE entity_number= '$entity_number'");
		
while ($row = mysqli_fetch_assoc($sql));
	$username = $row['username'];
    $entity_number= $row['entity_number'];	
    $entity_name= $row['entity_name'];		
/* close connection */

The form which is on the same page as the above query:
 

                <input type="hidden" class="form-control" value="<?php ECHO $_SESSION['username']; ?>" name="username" readonly>	

				<div class="form-group">
				    <label>Outlet Number :</label>
                      <input type="text" class="form-control" value="<?php ECHO $entity_number?>" name="entity_number">
				</div>

				<div class="form-group">
				    <label>Outlet Number :</label>
                      <input type="text" class="form-control" value="<?php ECHO $entity_name?>" name="entity_name">
				</div>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.