<?php  
	session_start();
	// ini untuk menyambungkan ke file lain
	include 'konek.php';
	// disini jika status udah login, bisa akses add-product
	// if($_SESSION['status_login'] !=true) {
		// echo '<script>window.location="login.php"</script>';
	// }

	
?>


<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Fixit - Explore new horizons</title>
	<link rel="stylesheet" type="text/css" href="profil.css">
	<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
	<script src="https://cdn.ckeditor.com/4.21.0/standard/ckeditor.js"></script>
</head>

<body>
	<!-- header -->
	<header>
		<div class="container">
	<h1><a href="database.php">FIXIT</a></h1>
	<ul>
		<li><a href="buying.php">Home</a></li>
		<li><a href="logout.php">Logout</a></li>
	</ul>
	</div>
	</header>

	<!-- container -->

<div class="section">
	<div class="container">
		<h3>Add Data Test Drive</h3>
		<div class="box">
			<!-- ini berkaitan dengan input upload data -->
			<form action="" method="POST" enctype="multipart/form-data">
				<input type="hidden" name="review_id" placeholder="Your Review ID" class="input-control" required>
				<input type="text" name="costumer_name" placeholder="Your Name" class="input-control" required>
				<input type="email" name="costumer_email" placeholder="Your Email" class="input-control" required>
				<input type="text" name="model" placeholder="Model Of The Vehicle" class="input-control" required>
				<input type="text" name="type_id" placeholder="Type of Vehicle" class="input-control" required>
				<textarea type="text" name="comment" placeholder="Write Your Review" class="input-control" required></textarea>
				<br>
				<input type="text" name="location" placeholder="Your Location" class="input-control" required>
				<br>

				<input type="submit" name="submit" value= "Add Data"class="btn">
			</form>


			<?php

					if (isset($_POST['submit'])) {

					$review_id      =$_POST['review_id']; 
					$costumer_name  =$_POST['costumer_name'];
					$costumer_email =$_POST['costumer_email'];
					$model          =$_POST['model'];
					$type_id        =$_POST['type_id'];
					$comment        =$_POST['comment'];
					$location       =$_POST['location'];

					//Mengeksekusi/menjalankan query diatas	
					  $nyimpan=mysqli_query($conn, "insert into review values ('$review_id', '$costumer_name', '$costumer_email', '$model', '$type_id', '$comment', '$location')");

					//Kondisi apakah berhasil atau tidak
					  if ($nyimpan) {
						echo 'Successfully Save Data';
						echo '<script>window.location="customer-testdrive.php"</script>';

					  }
					else {
						echo '<script>alert("Failed Save Data")</script>'.mysqli_error($conn);
						
					}  


			    }
			?>



		</div>
	</div>
</div>


	<!-- footer -->
<footer>
	<div class="container" id="footer">
		<small>Copyright & copy; 2023 - FIXIT.</small>
	</div>
</footer>


<!-- ini untuk text editor dibagian deskripsi -->
<script>
        CKEDITOR.replace( 'comment' );
</script>

	
</body>
</html>