I have gotten my form to search my SQL db table and return a row:
<?php
if(isset($_POST["Bearch"])){
$sql = "SELECT * FROM $table WHERE Name='$Name'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<th>".$row["Name"]."<th>". $row["MAC"]."<th>". $row["Own"]."<th>". $row["Type"]."<th>". $row["Model"]."<th>". $row["OS"]."<th>". $row["Office"]."<th>". $row["Us"]."<th>". $row["Building"]."<th>". $row["BKP"]."<th>". $row["WSUS"]."<th>". $row["SMC"]."<th>". $row["SSO"]."<th>". $row["CBS"]."<th>". $row["Decom"];
echo "</tr>";
}
} else {
echo "0 results";
}}
?>
However, I would like the form to fill in the input text boxes instead. Does anyone know how I would go about this?
I have tried several different ways of getting the value to display the fields but the result is always the same; The fields that I entered in to the text boxes stays instead of changing to what the db has for those fields.
Device Name: <input type="text" id="myInput" required="required" name="Name" autofocus="true" onBlur="
// I've tried this as a function as well.
<?php $sql="SELECT * FROM $table WHERE Name = $Name;";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$Name=$row["Name"];
$MAC=$row["MAC"];
$Own=$row["Own"];
$Type=$row["Type"];
$Model=$row["Model"];
$OS=$row["OS"];
$Off=$row["Office"];
$Us=$row["Us"];
$_POST["Build"]=$row["Building"];
$_POST["BKP"]=$row["BKP"];
$_POST["WSUS"]=$row["WSUS"];
$_POST["SMC"]=$row["SMC"];
$_POST["SSO"]=$row["SSO"];
$_POST["CBS"]=$row["CBS"];
$_POST["Decom"]=$row["Decom"];
}
};?>" value=<?php echo $Name ?>>
MAC Address: <input type="text" id="myInput" name="MAC" value="<?php echo $_SESSION["MAC"]; ?>">
Owner or Location: <input type="text" name="Own" value="<?php echo htmlspecialchars($Own); ?>">
I am expecting the text boxes to display their respective fields from the database, onBlur from the "Name" field, but nothing (no text appearing in the text box) seems to happen.