<?php include 'header-link.php' ?>
<?php 
        
    // Check if the form is submitted
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        $Title = $_POST['Title'];
        $Msg = $_POST['Msg'];
        $Date = $_POST['Date'];
        


        // Insert the new offer data into the database
        $insertSql = "INSERT INTO money_rate (title, message, date) 
                                            VALUES (?, ?, ?)";
        
        $stmt = $con->prepare($insertSql);
        $stmt->bind_param("sss", $Title, $Msg,$Date);

        if ($stmt->execute()) {
            $success_message = "New Rate Added Successfully.";
        } else {
            $error_message = "Error: " . $stmt->error;
        }

        $stmt->close();
    }
?>


    <main>
	
        <section>   
			<div class="container">
				<div class="row justify-content-center">
					<div class="col-md-6">
						<div class="card custom-card">
							<div class="card-body">
								<h6 class="card-title text-center d-block"> Add New Rate </h6>
                                        <?php if (!empty($success_message)): ?>
                                            <div class="alert alert-success"><?php echo $success_message; ?></div>
                                            <?php endif; ?>
                                            <?php if (!empty($error_message)): ?>
                                                <div class="alert alert-danger"><?php echo $error_message; ?></div>
                                        <?php endif; ?>
								
									<form class="form" action="" method="POST">

                                        <div class="mb-3">
                                            <label class="form-label"> Title </label>
                                                <input type="text" name="Title" class="form-control" value="আজকের টাকার রেট" required>
                                                
										</div>

                                        <div class="mb-3">
                                            <label class="form-label"> Rate </label>
                                                <textarea type="text" name="Msg" class="form-control" row="5" value="Write here..." ></textarea>
                                                
										</div>

                                        <div class="mb-3">
                                            <label class="form-label"> Date </label>
												<input type="date" name="Date" class="form-control" value="<?php echo date('Y-m-d'); ?>" required>
											
                                        </div>

										
										
										<button type="submit" class="btn custom-button"> Save  </button>
									</form>
									
							</div>
						</div>
					</div>
				</div>
			</div>
		</section>
		

		
    </main>

    
</body>
</html>
