PHP Form with jQuery DatePicker -
i building mvc php web app mysql. using form collect information user. date input works when date information input in correct order want more user friendly less tech savvy coworkers (god bless'em).
here form in 'index.php':
if($action == 'add_order'){ $distributor_id = filter_input(input_post, 'distributor_id', filter_validate_int); $code = filter_input(input_post, 'code'); $name = filter_input(input_post, 'name'); $date = filter_input(input_post, 'date'); if($distributor_id == null || $distributor_id == false || $code == null || $name == null || $date ==null){ $error = "invalid order data: wrong"; include('../errors/error.php'); }else{ add_order($distributor_id, $code, $name, $date); header("location: .?distributor_id=$distributor_id"); } } ?>
here form in 'order_add.php':
<h1>add order</h1> <form action="index.php" method="post" id="add_order_form"> <input type="hidden" name="action" value="add_order"> <label>distributor:</label> <select name="distributor_id"> <?php foreach ($distributors $distributor) : ?> <option value="<?php echo $distributor['distributorid']; ?>"> <?php echo $distributor['distributorname']; ?> </option> <?php endforeach; ?> </select> <br> <label>order code:</label> <input type="text" name="code"> <br> <label>customer name:</label> <input type="text" name="name"> <br> <label>order date:</label> <input type="text" id="date" name="date"> <br> <label> </label> <input type="submit" value="add order"> <br> </form> <p class="last_paragraph"> <a href="index.php?action=list_orders">view order list</a> </p> </main>
here view 'header_two_date_picker.php':
<!doctype html> <!-- header page going used order schedule php program , main_two.css--> <html> <!-- body section--> <head> <title>order status</title> <link rel='stylesheet' type='text/css' href = "../main_two.css"> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>jquery ui datepicker - default functionality</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <link rel="stylesheet" href="/resources/demos/style.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <script> $( function(){ $( "#date" ).datepicker(); } ); </script> </head> <!-- body section--> <body> <header> <h1>my php sandbox - date picker</h1> </header>
here model 'order_db.php'
function add_order($distributor_id, $code, $name, $date){ global $db; $query = 'insert orders (distributorid, ordercode, ordername, orderdate) values (:distributor_id, :code, :name, :date)'; $statement = $db->prepare($query); $statement->bindvalue(':distributor_id', $distributor_id); $statement->bindvalue(':code', $code); $statement->bindvalue(':name', $name); $statement->bindvalue(':date', $date); $statement->execute(); $statement->closecursor(); } ?>
the jquery datepicker displays , populates form field, table in db shows "0000-00-00".
my question this: how take datepicker data, , convert date format mysql store?
thank taking time @ question.
<------ first time posting if i'm doing wrong... whoops!----->
this part of 'order_list.php' file
<!-- display table of orders --> <h2><?php echo $distributor_name; ?></h2> <table> <tr> <th>order code</th> <th>order name</th> <th>order date</th> <th> </th> </tr> <?php foreach ($orders $order) : ?> <tr> <td><?php echo $order['ordercode']; ?></td> <td><?php echo $order['ordername'] ?></td> <td><?php echo $order['orderdate'] ?></td> <td><form action="." method="post"> <input type="hidden" name="action" value="delete_order"> <input type="hidden" name="order_id" value="<?php echo $order['orderid']; ?>"> <input type="hidden" name="distributor_id" value="<?php echo $order['distributorid']; ?>"> <input type="submit" value="delete"> </form></td> </tr> <?php endforeach; ?> </table> <p class = "last_paragraph"> <a href="?action=show_add_form">add order</a> </p> ***<h2>this test output $date: <?php echo $date; ?></h2> <h2>this test output echo $_post['date']: <?php echo*** $_post['date']; ?></h2>
if can past heinous styling of page see tests tried echo variables not displaying anything.
hello buhlahkay.
make sure using database structure date using date format.. date field mysql accepted
2017-12-30 (year-month-date)
.debug self code output
echo $_post['date'];
, @ date whether formatting database accepted format (year-month-date).modify date picker jquery
$('#date').datepicker({dateformat : 'yy-mm-dd'});
if displays format there no issue.. kindly re update codes index.php doing more detailed 1 1. avoid confusion..
Comments
Post a Comment