SalientAnimal Posted January 13, 2017 Share Posted January 13, 2017 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... Quote Link to comment https://forums.phpfreaks.com/topic/302920-populate-edit-form/ Share on other sites More sharing options...
SalientAnimal Posted January 13, 2017 Author Share Posted January 13, 2017 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> Quote Link to comment https://forums.phpfreaks.com/topic/302920-populate-edit-form/#findComment-1541332 Share on other sites More sharing options...
Barand Posted January 13, 2017 Share Posted January 13, 2017 You have $store_code = $_GET['entity_number']; So where does your variable $entity_number get its value from? Quote Link to comment https://forums.phpfreaks.com/topic/302920-populate-edit-form/#findComment-1541335 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.