
I have code to retrieve data from a database into a form but it doesnt seem to be working. The code below is my attempt but it doesnt work. Currently, when I click the submit button 'retrieve rose' it does nothing...
//if we have no errors, do the SQL
if (!$errors) {
$latin_name = $_POST['latin_name'];
$stmt = $conn2->prepare("SELECT common_name, variety_name, colour, season_of_interest, hardiness, situation, soil_type,
price, stock_level, fragrance, ultimate_height FROM rosename WHERE latin_name = ?");
$stmt->bind_param('ssssssssdiss', $latin_name);
if ($result = $stmt->get_result()) {
/* fetch associative array */
echo "<form><input type='text' value='" . $row["common_name"] . "' name='latin_name' />";
echo "<input type='text' value='" . $row["variety_name"] . "' name='soil_type' /></form>";
} // i no I need to add more here...
exit;
}
//put out the footer and then stop the rest of the script from running, so we don't display the rest of the form (this is after the form has been submitted)
require_once('footer.php');
exit;
}
//if we do have errors, show the error message
else {
echo "<p>".$error_msg."</p>";
}}
?>
And here is my form:
<h1>Update Rose Item</h1>
<ul class='register'>
<li>
<form action="updaterose.php" id="updaterose" method="post">
<fieldset id="register">
<label>Latin Name:<span class="small">Enter a Latin Name</span></label><input name='latin_name' id='latin_name' type='text' value="<?=(isset($_POST['latin_name'])? $_POST['latin_name']:"");?>" />
<input type="submit" value="Retrieve Rose" name='retrieverose' /></br></br></br>
</form>
Code requested by mariogl
//connect to database
$conn2 = DB2();
require_once('header_admin.php');
if (isset($_POST['updaterose']))
{
//detect if we have errors or not
$errors = false;
$error_msg = "Error, please try again";
} // i no I need to add more here...