Skip to content

Instantly share code, notes, and snippets.

@JamesVanWaza
Last active September 24, 2015 13:33
Show Gist options
  • Save JamesVanWaza/23c92050571932f2216e to your computer and use it in GitHub Desktop.
Save JamesVanWaza/23c92050571932f2216e to your computer and use it in GitHub Desktop.
Insert jQuery Date into MySQL
<body>
<form action="test.php" method="post">
<div class="row">
<div class="large-12-columns">
<fieldset>
<legend>Date of Presentation</legend>
<label for="">Presentation Date</label>
<input type="text" name="jquerydatepicker" class="selector" value="<?php if (isset($_POST['jquerydatepicker'])) {
echo $_POST['jquerydatepicker'];
}
?>" placeholder="When the event was held"/>
</fieldset>
</div>
<div class="large-12-columns">
<div class="row">
<div class="small-12 medium-12 large-12 columns">
<button class="tiny round right firstbutton" name="button">Next Page <i class="fa fa-angle-double-right"></i></button>
</div>
</div>
</div>
</div>
</form>
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="bower_components/foundation/js/foundation.min.js"></script>
<script type="text/javascript" src="bower_components/chosen/chosen.jquery.min.js"></script>
<script type="text/javascript" src="https://use.typekit.net/yiz1wur.js"></script>
<script type="text/javascript">try{Typekit.load({ async: true });}catch(e){}</script>
<script src="jquery-ui-1.11.4/jquery-ui.min.js"></script>
<script>
jQuery(document).ready(function($) {
$(document).foundation();
$(".selector").datepicker({
dateFormat: "yy-mm-dd"
});
});
</script>
<?php require 'mysqli-connect.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
/** Variables */
$pdate = isset($_POST['jquerydatepicker']) ? $_POST['jquerydatepicker'] : '';
$q = "INSERT INTO `testdate` (id, pdate, date_created)
VALUES (NULL, '$pdate', NOW())";
$result = @mysqli_query($dbcon, $q); /** Run the Query **/
if ($result) {
// If it ran OK.
echo var_dump($_POST);
echo '<div data-alert class="alert-box">
Success, 1 step completed !!! 3 to Go
<a href="#" class="close">&times;</a>
</div>';
exit();
} else {
// Public message:
echo '<div data-alert class="alert-box alert">
You could not be registered due to a system error. We apologize for any inconvenience.
<a href="#" class="close">&times;</a>
</div>';
// Debugging message:
echo '<p class="text-center error">' . mysqli_error($dbcon) . '<br><br>Query: ' . $q . '</p>';
} // End of if ($r) IF.
}
?>
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="bower_components/foundation/js/foundation.min.js"></script>
<script type="text/javascript" src="https://use.typekit.net/yiz1wur.js"></script>
<script type="text/javascript">try{Typekit.load({ async: true });}catch(e){}</script>
<script src="jquery-ui-1.11.4/jquery-ui.min.js"></script>
<script>
jQuery(document).ready(function($) {
$(document).foundation();
});
</script>
<?php include 'footer.php';?>
@JamesVanWaza
Copy link
Author

@foundationphp, It is working now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment