Hi Dave,

Let's look and see)
1. You can re-format your date so that it will fit the needed format
for MySql:
$_POST['EndDate']=date("Y-m-d", $_POST['EndDate']);

                                                 2. There's a PHP
                                                 function called
                                                 isset() that checks
                                                 whether a variable is
                                                 set. But you probably
                                                 will find this one
                                                 much handier:
if (!empty($_POST['EndDate'])) {
// blahblah, inserting into database

3. This is quite simple, I think. You write:
<option>Choice 1</option>
What would you like PHP to write in the DB? It has nothing to write at
all) You should do this instead:
<option value=1>Choice 1</option>
<option value=2>Choice 2</option>

So now you have values to insert)
Hope I could help you!)

With best regards from Ukraine,
Skype: Francophile; Wlm&MSN: arthaelon @ yandex.ru; Jabber: arthaelon @ 
Yahoo! messenger: andre.polykanine; ICQ: 191749952
Twitter: m_elensule

----- Original message -----
From: David Mehler <dave.meh...@gmail.com>
To: php-general <php-general@lists.php.net>
Date: Wednesday, June 2, 2010, 11:20:55 PM
Subject: [PHP] Inserting, storing, outputting dates and selections

I've got two questions which are probably fairly simple, my issue is
i'm staring at this so long it's blurring together.
        I'm working on a form to insert data in to a mysql database. I've got
a startdate and and enddate field in the database both of type DATE,
i'm needing this as i'm wanting to do a calculation against the date
and only display records greater than or equal to the current date. My
understanding is dates have to be entered as 2010-06-02 with this
        I'm having several issues: the first of which is I entered a date as
probably a user would as June 2, 2010 and on the display page got all
zeroes, is there a way i can be more flexible with my data entry,
enter it, then store it in the format mysql needs?
My second issue is that the startdate field is NOT NULL while the
enddate field is. On submission I only want those forms that are
actually in the post data to get inserted in to the database, and
displayed, i.e. if enddate was not entered I shouldn't see all zeroes
in the field in the database, if using the mysql commandline client,
or all zeroes in displayed output. I'm not sure how to conditionally
insert or display a field based on whether it's set.
My last issue, not on dates, is on a selection box. I've got two
choices to choose from, choice1 and choice2 just for this example. If
a user goes through and selects nothing I want choice1 to be
automatically selected on form submission, if a user selects choice2
then the form should go with that. Here's my code.

<label for="txtchoose">Choose*:</label>
<select name="Choice for Selection">
<option> - choice1 - </option>
<option> - choice2 - </option>

On form submission the php script processes it and enters an empty
field in the database if the user doesn't select an option.

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to