0

My Form:

enter image description here

I'm creating a web based product database which features an edit page, I currently have a drop down menu which displays all of the products stored in the SQL database. Is it possible to make the text-boxes on the page auto-fill with the corresponding data when the product is selected?

Any help appriciated.

The code for my edit page is as follows:

<?php

session_start(); 

//CREATES & CHECKS MySQL CONNECTION

$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) 

{
die("Connection failed: " . mysqli_connect_error());
}

$sql = "SELECT * FROM PRODUCTS LIMIT 0 , 30";
$result = mysqli_query($conn, $sql);

?>

<!-- HTML PAGE PROPERTIES -->

<div id="left"></div> 
<div id="right"></div>
<div id="top"></div>
<div id="bottom"></div>  
<div align="center"><h1>PRODUCT DATABASE</h1>
<div align="center"><a href="index.php">HOME&nbsp; <i class="fa fa-home"      aria-hidden="true"></i></a><br>
<div align="left"><link rel="stylesheet" type="text/css"     href="styleSheet.css"> 
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font- awesome/4.4.0/css/font-awesome.min.css"> 

<?php

print "<h3>EDIT PRODUCT</h3>"; 

print "<p>&nbsp;<strong>SELECT PRODUCT: </strong>";
$conn = new mysqli() 
or die ('Cannot connect to db');

$result = $conn->query("select ID, NAME from PRODUCTS");

echo "<html>";
echo "<body>";
echo "<select name='ID'>";

while ($row = $result->fetch_assoc()) {

              unset($id, $name);
              $id = $row['ID'];
              $name = $row['NAME']; 
              echo '<option value="'.$id.'">'.$name.'</option>';

}

?>


</select>
<form method='POST'>
<h3>PRODUCT:</h3>
<input type='textbox' name='product' value='<?php echo $product['product'] ? >'> 
<h3>ID:</h3>
<input type='textbox' name='id' value='<?php echo $product['id'] ?>'>
<h3>BARCODE:</h3>
<input type='textbox' name='barcode' value='<?php echo $product['barcode']; ?>'>
<h3>TYPE:</h3>
<select name="type">
<option value=""></option>
<option value="A">A</option> 
<option value="B">B</option>
<option value="C">C</option>
</select></p>
<input type='submit' value='Save Changes' name=submitform> 

<?php

//WHEN EDIT BUTTON IS PRESSED, SEND EDITED VARIABLE VALUES TO MySQL

if (isset($_POST['submitform']))

{


}     
Shadow
  • 33,525
  • 10
  • 51
  • 64
bbowesbo
  • 885
  • 1
  • 7
  • 17

1 Answers1

0

To have your form autofill you will need to use an asynchronous technology that allows for communication between your front end and your backend / database. When using AJAX (or websockets) it allows for communication wihtout having to reload the whole page. This is exactly the functionality you're looking for. I suggest using AJAX.

Take a look at this post.

Community
  • 1
  • 1
Jonathan Eustace
  • 2,469
  • 12
  • 31
  • 54