<?php
	if(isset($_POST['breed'])) {
		$breed = $_POST['breed'];
		$age = $_POST['age'];
		$habit = $_POST['habit'];
		$breedpeople = $_POST['breedpeople'];
		$general = $_POST['general'];
		$care = $_POST['care'];
		$should_know = $_POST['should_know'];
		$picture = $_FILES['picture'];
		$video = $_POST['video'];

		$file_name = $_FILES['picture']['name'];
    $file_size =$_FILES['picture']['size'];
    $file_tmp =$_FILES['picture']['tmp_name'];
    $file_type=$_FILES['picture']['type'];
		$file_ext=strtolower(end(explode('.',$_FILES['picture']['name'])));
		$path="images/".time().$file_name;
		move_uploaded_file($file_tmp, $path);

		include('includes/config.php');
		$sql = "INSERT INTO `dogs` VALUES (default,'$path', '$breed', '$age','$video', '$habit', '$breedpeople', '$general', '$care', '$should_know')";
		$result = mysqli_query($conn, $sql);
		if(mysqli_affected_rows($conn)>=0){
    	header('Location:page5.php');
	  }else{
	    echo mysqli_error($conn);
	  }

	  mysqli_close($conn);
	}
?>

<?php include('layouts/header.php'); ?>
<div class="container">
	<div class="row">
		<div class="offset-sm-3 col-sm-6">
			<h1 class="text-center text-info my-2">เพิ่มข้อมูลสุนัข</h1>
			<form action="createDog.php" method="post" enctype="multipart/form-data">
				<div class="form-group row">
			    <label for="breed" class="col-sm-3 col-form-label">สายพันธุ์ :</label>
			    <div class="col-sm-9">
			      <input type="text" name="breed" class="form-control"  id="breed" size="20" required>
			    </div>
			  </div>
				<div class="form-group row">
			    <label for="age" class="col-sm-3 col-form-label">ช่วงอายุ :</label>
			    <div class="col-sm-9">
			      <input type="text" name="age" class="form-control"  id="age" size="20" required>
			    </div>
			  </div>
				<div class="form-group row">
			    <label for="habit" class="col-sm-3 col-form-label">ลักษณะนิสัย :</label>
			    <div class="col-sm-9">
			      <input type="text" name="habit" class="form-control"  id="habit" size="20" required>
			    </div>
			  </div>
				<div class="form-group">
			    <label for="breedpeople">สายพันธุ์ที่เหมาะสมกับผู้เลี้ยง :</label>
					<textarea name="breedpeople" rows="8" class="form-control"  cols="80" id="breedpeople" required></textarea>
			  </div>
				<div class="form-group">
			    <label for="general">ลักษณะทั่วไป :</label>
					<textarea name="general" rows="8" class="form-control"  cols="80" id="general" required></textarea>
			  </div>
				<div class="form-group">
			    <label for="care">การดูแลสุนัข :</label>
					<textarea name="care" rows="8" class="form-control"  cols="80" id="care" required></textarea>
			  </div>
				<div class="form-group">
			    <label for="should_know">ข้อควรรู้ :</label>
					<textarea name="should_know" rows="8" class="form-control"  cols="80" id="should_know" required></textarea>
			  </div>
				<div class="form-group row">
			    <label for="picture" class="col-sm-3 col-form-label">รูปภาพ :</label>
			    <div class="col-sm-9">
						<div class="custom-file">
						  <input type="file" class="form-control" name="picture" id="picture" required>
						</div>
			    </div>
			  </div>
				<div class="form-group row">
			    <label for="video" class="col-sm-3 col-form-label">วิธีการเตรียมตัวก่อนเลี้ยงสุนัข :</label>
			    <div class="col-sm-9">
			      <input type="text" name="video" class="form-control"  id="video" size="20" required>
			    </div>
			  </div>
				<p class="text-center">
					<button type="submit" class="btn btn-success">เพิ่มข้อมูล</button>
				</p>
			</form>
		</div>
	</div>
</div>
<?php include('layouts/footer.php'); ?>
