0

Hello.

So, I have 2 questions.

First is:

I am trying to calculate the expiration date which will be calculated as adding the current date + the option that has been select i.e. 30, 60 or 90 days.

    $EXday = date('d', mktime(0,0,0,0, date(d) + $_POST[exdays], 0));
    $EXmonth = date('m', mktime(0,0,0, date(m), date(d) + $_POST[exdays], 0));
    $EXyear = date('Y', mktime(0,0,0,date(m) ,date(d) + $_POST[exdays], date(Y)));





<tr>
    <td>

    This offer expire after: 
    </td>

    <td>
    <select name="exdays">
    <option value="30"> 30 </option>
    <option value="60"> 60 </option>
    <option value="90"> 90 </option>
    </select>
     days. 
    </td>
    </tr>

2nd question is:

When I perform my Insert Statement, instead of getting a value in one of the field I get "Array", but the rest of statement seems to be ok.

I am using a radio button similar to the one I just posted about the expiration date.

Edited by SQLpower

4
Contributors
5
Replies
26
Views
4 Years
Discussion Span
Last Post by SQLpower
0

Firstly, u need to have the posted data in single quotes like so;

$EXday = date('d', mktime(0,0,0,0, date('d') + $_POST['exdays'], 0));

Do the same to the other records

Edited by Webville312

0

Regarding the date try:

date('d-m-Y', mktime(0, 0, 0, date("m"), date("d") + $_POST['exdays'], date("Y")));

Concerning the second question, you can use json_encode() to convert the array to a string and so, you can save it as varchar or text type, otherwise you need a blob type.

Edit
Sorry Webville, I just saw your reply, bye!

Edited by cereal

0

I'd suggest DateTime object as thast deals easily with overflows too:

$x = (int) $_POST['exdays'];
if(in_array($x, array(30,60,90)){
    $date = new DateTime();
    $date->add(new DateInterval('P'.$x.'D'));
    echo "NEW DATE: " . $date->format('Y-m-d') . "\n";
};
0

Thank you guys, it works like a charm.

Just using Webville's suggestion fixed both of my problems, hah.

Diafol, thank you for the suggestion. I'll have a look at it.

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.