0
Index.php
<html>
<head><title>Registration</title>
<script type="text/javascript">
function numbersonly(e,length){
var unicode=e.charCode? e.charCode : e.keyCode
var maxlength=length;
if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
if (unicode<48||unicode>57) //if not a number
return false //disable key press
}
}
</script>
<script type="text/javascript">
function validation()
{
var a = document.form.phone.value;
if(a=="")
{
alert("Please Enter Your Phone Number");
document.form.phone.focus();
return false;
}
}
</script>
<script type="text/javascript">  
      var reg = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;  
      function PhoneValidation(phone)
      {  
        var OK = reg.exec(phone.value);  
        if (!OK)  
          window.alert("phone number isn't  valid");  
        else  
          window.alert("phone number is  valid");  
      }  
    </script>  
    <script language="javascript">

function checkEmail() {

    var email = document.getElementById('email');
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{3})+$/;

    if (!filter.test(email.value)) {
    alert('Please provide a valid email address');
    email.focus;
    return false;
 }
}</script>
</head>
<body>
<div align="center">
<h3> Registration</h3>
<form name="register" action="save.php" enctype="multipart/form-data" onsubmit="return validation()" method="post">
<label>Name</label>
<label>:</label>
<input type="text" name="name" id="name" placeholder="Name" required/><br /><br />
<label>Email</label>
<label>:</label>
<input type="email" name="email" id="email" placeholder="Email" required/><br /><br />
<label>Password</label>
<label>:</label>
<input type="password" name="password" id="password" placeholder="Password" required/><br /><br />
<label>RepeatPassword</label>
<label>:</label>
<input type="password" name="repeatpassword" id="repeatpassword" placeholder="RepeatPassword" required/><br /><br />
<label>Date of Birth</label>
<label>:</label>
<select name="day" required>
<option value="">Day</option>
<?php for ($day = 1; $day <= 31; $day++) { ?>
<option value="<?php echo strlen($day)==1 ? '0'.$day : $day; ?>"><?php echo strlen($day)==1 ? '0'.$day : $day; ?></option>
<?php } ?>
</select>
<select name="month" required>
<option value="">Month</option>
<?php for ($month = 1; $month <= 12; $month++) { ?>
<option value="<?php echo strlen($month)==1 ? '0'.$month : $month; ?>"><?php echo strlen($month)==1 ? '0'.$month : $month; ?></option>
<?php } ?>
</select>
<select name="year" required>
<option value="">Year</option>
<?php for ($year = date('Y'); $year > date('Y')-100; $year--) { ?>
<option value="<?php echo $year; ?>"><?php echo $year; ?></option>
<?php } ?>
</select><br /><br />
<label>Phone</label>
<label>:</label>
<input type="text" name="phone" id="phone" placeholder="Phone No" maxlength="10" onKeyPress="return numbersonly(event)" onchange="PhoneValidation(this);"  required/><br /><br />

<input type="submit" name="submit" value="Register" onClick="return checkEmail()"/>
</form>
</div>
</body>
</html>

save.php:::

<?php
include('connect.php');
$name=$_POST['name'];
$email=$_POST['email'];
$password=$_POST['password'];
$repeatpassword=$_POST['repeatpassword'];
$phone=$_POST['phone'];
$date = $_POST['day'] . '/' . $_POST['month'] . '/' . $_POST['year'];

$sql=mysql_query("insert into  register(name,email,password,repeatpassword,phone,date)values('$name','$email','$password','$repeatpassword','$phone','$date')") or die(mysql_error());
echo "<script type='text/javascript'>alert('Data Inserted Successfully'); window.location.href='index.php';</script>";
?>

my question is, it inserts all the values in the database except date of birth, 
values are storing like :
id  username  email              password         repeatpassword     phone      date
7   akbar   akbarbai@gmail.com  baiakbar    baiakbar    2147483647  0000-00-00.
How to solve this...
I need:
    7  akbar  akbarbai@gmail.com  baiakbar baiakbar 2147483647  20/12/2015

Edited by AntonyRayan: nil

3
Contributors
3
Replies
15
Views
2 Years
Discussion Span
Last Post by AntonyRayan
0

prit is right about the format, because if MySQL has a "date" field, it wants it in yyyy-mm-dd and will reject anything else.

Also, why on earth are you storing
a) a password with no apparent hashing or encryption??? Major security problem.
b) the repeat password? You won't ever look at it after validation so what's the use in storing the same thing twice?

While I'm on security, you have no escaping, so you are vunerable to "SQL injection" - might be worth looking at that.

Finally to note, mysql_query() was deprecated as of PHP 5.5, so you really ought to at least look at PDO or mysqli.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.