sandeep S K
sandeep S K

Reputation: 36

warning mktime() expects parameter 4 to be long string

  warning mktime() expects parameter 4 to be long string

This is the error I am getting when I try to store Date of birth into a mysql database.

Here is the HTML code:

 <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Registration</title>
    <link href='http://fonts.googleapis.com/css?family=Josefin+Sans' rel='stylesheet' type='text/css'>
    <style>
    #container{
    width:350px;
    height:auto;
    float:left;
    font-family: 'Josefin Sans', sans-serif;
    color:#82ABEA;
    }
    label{
    display:block;
    margin-bottom:5px;
    }
    fieldset{
    border-color:#82ABEA;
    }
    button{
    background-color:#900;
    color:#FFF;
    border:none;
    box-shadow:none;
    width:80px;
    height:30px;
    }
    </style>
    </head>

    <body>
    <div id="container">
    <form method="post" action="save_reg.php">
    <fieldset>
    <legend><b>Register Here</b></legend>


    <label>Date Of Birth</label>
    <select name="db">
    <option selected>Month</option>
    <option>January</option>
    <option>February</option>
    <option>March</option>
    <option>April</option>
    <option>May</option>
    <option>June</option>
    <option>July</option>
    <option>August</option>
    <option>September</option>
    <option>October</option>
    <option>November</option>
    <option>December</option>

    </select>
    <select name="dbd">
    <option selected>Day</option>
    <option>01</option>
    <option>02</option>
    <option>03</option>
    <option>04</option>
    <option>05</option>
    <option>06</option>
    <option>07</option>
    <option>08</option>
    <option>09</option>
    <option>10</option>
    <option>11</option>
    <option>12</option>
    </select>

    <select name="dby">
    <option selected>Year</option>
    <option>2005</option>
    <option>2006</option>
    <option>2007</option>
    <option>2008</option>
    <option>2009</option>
    <option>2010</option>
    <option>2011</option>
    <option>2012</option>
    <option>2013</option>
    <option>2014</option>
    <option>2015</option>
    <option>2016</option>
    </select><br/><br/>

    <button><b>Submit</b></button>
    </fieldset>
    </form>
    </div>
    </body>
    </html>

And here is The Php code I have used:

<?php 
$connection = mysqli_connect("localhost" , "root" , "", "register");
if(mysqli_connect_errno()){
    echo"Connection Failed" . mysqli_connect_errno();
}else{
echo "Connection Succesfull";
}

$db= $_POST['db'];
$dbd= $_POST['dbd'];
$dby= $_POST['dby'];

$date = date("Y-m-d", mktime(0,0,0,$db, $dbd, $dby));

$sql = "INSERT INTO register_form(dateb) VALUES('$date')";

if(!mysqli_query($connection, $sql)){
echo"Data is not saved";
}else{
echo $_POST['firstname'] . " " . $_POST['lastname'] . "your data is saved";
}

Can someone please guide me to add date of birth to the database?

Upvotes: 2

Views: 11952

Answers (2)

Kevin
Kevin

Reputation: 41873

Since you need to input months as their numerical representation, you need the dropdown values of months like this:

<option disabled selected>Month</option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>

So that when you use mktime(), it will be the correct parameter to the months.

int mktime ([ int $hour = date("H") [, int $minute = date("i") [, int $second = date("s") [, int $month = date("n") [, int $day = date("j") [, int $year = date("Y") [, int $is_dst = -1 ]]]]]]] )

Look at the month parameter. It needs the format date('n') which equivalents to:

Numeric representation of a month, without leading zeros

Obligatory note:

Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

Upvotes: 1

Rasclatt
Rasclatt

Reputation: 12505

Your drop down options for db should have numeric values.

Upvotes: 0

Related Questions