Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

How do i make a PHP form use a specific date format Mask / Validation....

Avatar of Scott Johnston
Scott JohnstonFlag for United States of America asked on
HTMLPHPMySQL Server
12 Comments1 Solution911 ViewsLast Modified:
I------have a simple data entry form that I would like to be able to have the Date and Time field be validated so it is on the correct format when being added to the database.  We use this date time field to turn on or off special pricing on products.
In the code below I enter the Starting Date in the correct format "YYYY/MM/DD 00:00:00" on my form and it write to the data base.  I like to have that field "StartingDate" validated on submit.
What is the best solution for this type of validation?

here is my test form:
-------------------------------------------------------------------------------------
<html>
 <head>
 </head>
 <body>
 <form action="insert.php" method="post">
 Item Number: <input type="text" name="ItemNumber">
 Sale Start Date: <input type="datetime" name="StartingDate">
 Sale End Date: <input type-"datetime" name="EndingDate">
 Sale Price: <input type="text" name="SalePrice">
 <input type="submit" name="submit">
 </form>

 


<?php
if (isset($_POST['submit'])){                                              /*only if the submit buttonis presseed*/


 $con = mysql_connect("Datebase location","Logon Name","Passowrd");
 // Check connection
 if (!$con) {
   die ('Could not Connect to MySQL: ' . mysql_error());
 }

mysql_select_db("biomas",$con);
 // escape variables for security
/*$ItemNumber = ($con, $_POST['ItemNumber']);
$StartingDate = ($con, $_POST['StartingDate']);
$EndingDate = ($con, $_POST['EndingDate']);
$SalePrice = ($con, $_POST['SalePrice']);  */

$sql = "INSERT INTO ITProductSale (ItemNumber, StartingDate, EndingDate, SalePrice)
VALUES ('$_POST[ItemNumber]','$_POST[StartingDate]','$_POST[EndingDate]','$_POST[SalePrice]')";

mysql_query ($sql, $con);

/*if (!mysqli_query($con,$sql)) {
  die('Error: ' . mysqli_error($con)); */

echo "1 record added";

mysql_close($con);
}
 ?> 

</body>
 </html>

-------------------------------------------------------------------------