<?php
require('db.php');
include("auth.php"); //include auth.php file on all secure pages
$status = "";
if(isset($_POST['new']) && $_POST['new']==1)
{
$trn_date = date("Y-m-d H:i:s");

$Plant_name =$_REQUEST['Plant_name'];
$Soil = $_REQUEST['Soil'];
$water = $_REQUEST['water'];
$Fertility = $_REQUEST['Fertility'];
$Sunlight =$_REQUEST['Sunlight'];
$Days_to_germinate = $_REQUEST['Days_to_germinate'];
$Days_to_harverst = $_REQUEST['Days_to_harverst'];
$Seedings = $_REQUEST['Seedings'];
$Seeds = $_REQUEST['Seeds'];
$Overview = $_REQUEST['Overview'];
$Growing_notes = $_REQUEST['Growing_notes'];
$Maintaining = $_REQUEST['Maintaining'];
$Saving_seeds = $_REQUEST['Saving_seeds'];

$submittedby = $_SESSION["username"];



$sql1="insert into Planted(`plant_name`,`planted_date`)values('$Plant_name','$trn_date')";
$sql2="insert into Plants(`plant_name`,`picture`, `Overview`, `growing_note`, `maintaning`, `saving_seeds`)values('$Plant_name','$Plant_name', '$Overview', '$Growing_notes', '$Maintaining', '$Saving_seeds')";
$sql3="insert into Seeds(`plant_name`,`germination`,`soil`,`water`,`Fertility`, `sunlight`,`days_to_harvest`, `Seedings`, `Seeds`)values('$Plant_name','$Days_to_germinate','$Soil','$water','$Fertility','$Sunlight','$Days_to_harverst', '$Seedings', '$Seeds')";


mysql_query($sql1) or die(mysql_error());
mysql_query($sql2) or die(mysql_error());
mysql_query($sql3) or die(mysql_error());

$status = "New Record Inserted Successfully.</br></br><a href='view.php'>View Inserted Record</a>";
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert New Record</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div class="form">
<p><a href="dashboard.php">Dashboard</a> | <a href="view.php">View Records</a> | <a href="logout.php">Logout</a></p>
<div>
<h1>Insert New Record</h1>
<form name="form" method="post" action=""> 
<input type="hidden" name="new" value="1" />

<p><input type="text" name="Plant_name" placeholder="Enter Plant Name" required /></p>

<p>
<select name="water">
  <option value="" disabled selected>Select Water requirment</option>
  <option name="water" value="little_water">Dry</option>
  <option name="water" value="middlte_water">Middle watering</option>
  <option name="water" value="lot_water">Moist</option>
</select></p>

<select name="Sunlight">
  <option value="" disabled selected>Select Sun Requirement</option>
  <option name="Sunlight" value="shade">Shade</option>
  <option name="Sunlight" value="half_shade">Half Shade</option>
  <option name="Sunlight" value="full_sun">Full Sun</option>
</select></p>

<select name="Soil">
  <option value="" disabled selected>Select Soil Type</option>
  <option name="Soil" value="Sandy">Sandy</option>
  <option name="Soil" value="test">test</option>
</select></p>

<select name="Fertility">
  <option value="" disabled selected>Select Fertility Requirment</option>
  <option name="Fertility" value="Fertile">Fertile</option>
  <option name="Fertility" value="test">test</option>
</select></p>

<p><input type="text" name="Days_to_germinate" placeholder="Enter Days to germinate"/></p>
<p><input type="text" name="Days_to_harverst" placeholder="Days to harverst" /></p>

<p><input type="text" name="Seeds" placeholder="Enter Plant Seeds" /></p>
<p><input type="text" name="Seedings" placeholder="Enter Seedings Distance" /></p>


<p><input type="text" name="Overview" placeholder="Plant's Overview" /></p>
<p><input type="text" name="Growing_notes" placeholder="Plant's Growing Notes" /></p>
<p><input type="text" name="Maintaining" placeholder="Plant's Harvesting" /></p>
<p><input type="text" name="Saving_seeds" placeholder="Plant's Saving Seeds" /></p>

<p><input name="submit" type="submit" value="Submit" /></p>
</form>
<p style="color:#FF0000;"><?php echo $status; ?></p>
</div>
</div>
</body>
</html>
