Kashif Ali

Kashif Ali

  • 1.9k
  • 78
  • 2.8k

How to pass datepicker value in form POST methed to PHP ?

Dec 5 2018 4:53 AM
here's my HTML form
  1. <meta charset="utf-8">  
  2. <meta name="viewport" content="width=device-width, initial-scale=1">  
  3. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">  
  4. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>  
  5. <script type="text/javascript">  
  6. $(function () {  
  7. $('#datetimepicker1').datetimepicker();  
  8. });  
  9. </script>  
  10. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>  
  11. <!-- <link rel="stylesheet" type="text/css" href="css/bootstrap-datetimepicker.css"> -->  
  12. <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment.min.js"></script>  
  13. <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.43/css/bootstrap-datetimepicker.min.css">  
  14. <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.43/css/bootstrap-datetimepicker-standalone.css">  
  15. <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.43/js/bootstrap-datetimepicker.min.js"></script>  
  16. <script>  
  17. $(document).ready(function(){  
  18. $('[data-toggle="tooltip"]').tooltip();  
  19. });  
  20. </script>  
  21. <form action="one.php" method="POST">  
  22. <div class="col-md-6">  
  23. <div class="form-group">  
  24. <label for="name">Event Title:</label>  
  25. <input type="text" class="form-control" id="first_name" placeholder="Should be 10 character" required="" name="title" maxlength="10" >  
  26. </div>  
  27. <div class="form-group">  
  28. <label for="name">Client Name:</label>  
  29. <input type="text" class="form-control" id="first_name" placeholder="Enter Name" name="name" >  
  30. </div>  
  31. <div class="form-group">  
  32. <label for="text">Task:</label>  
  33. <input type="text" class="form-control" name="task" placeholder="Enter Task">  
  34. </div>  
  35. </div>  
  36. <div class="col-md-6">  
  37. <div class="form-group">  
  38. <label for="text">Set Date & Time:</label>  
  39. <div class="form-group">  
  40. <div class='input-group date' id='datetimepicker1' name="datepicker" value="date">  
  41. <input type='text' class="form-control" id="datepicker1" name="datepicker" value="date"/>  
  42. <span class="input-group-addon">  
  43. <span class="glyphicon glyphicon-calendar"></span>  
  44. </span>  
  45. </div>  
  46. </div>  
  47. </div>  
  48. <div class="form-group">  
  49. <label for="text">Department:</label>  
  50. <input type="text" class="form-control" name="department" placeholder="Select department " >  
  51. </div>  
  52. <div class="form-group">  
  53. <label for="text">Assign to:</label>  
  54. <input type="text" class="form-control" name="assign" placeholder="Select" >  
  55. </div>  
  56. <br><br>  
  57. <button type="submit" name="submitform" class="btn btn-default" style="float:right;width:auto; padding:10px; font-size:16px; background-color:rgba(0,0,0,0.8); color:white;">Submit</button>  
  58. </form>  
AND Here's PHP
  1. <?php  
  2. $servername = "localhost";  
  3. $username = "root";  
  4. $password = "";  
  5. $db = "admin";  
  6. // Create connection  
  7. $conn = new mysqli($servername,$username,$password,$db);  
  8. if(isset($_POST['submitform'])){  
  9. $title = $_POST['title'];  
  10. $name = $_POST['name'];  
  11. $department = $_POST['department'];  
  12. $task = $_POST['task'];  
  13. $date =$_POST['datepicker'];  
  14. $assign = $_POST['assign'];  
  15. $now =date('m/d/Y h:i:s a', time());  
  16. $query = "CREATE EVENT IF NOT EXISTS $title  
  17. ON SCHEDULE AT '$date'  
  18. DO  
  19. INSERT INTO task(name,department,task,assign,deadline,created_at) VALUES ('$name','$department','$task','$assign','$date','$now')  
  20. ;";  
  21. mysqli_query($conn,$query);  
  22. echo "<center><br>Event has been created.<br/> You're notified that this will be fired automatically on your set date !<br/><br/>Redirecting back in 5 seconds ...";  
  23. header("Refresh: 1; url=test2.php");  
  24. mysqli_close($conn);  
  25. };  
  26. ?>  
Please guide, Please

Brought to you by: JavaScript SDK for Bold BI dashboard and analytics embedding. Free trial.

Answers (1)