Form, Date question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cooler75
Forum Commoner
Posts: 40
Joined: Wed May 29, 2002 2:43 pm
Location: RichIsland

Form, Date question

Post by cooler75 »

Hi,
I am learning to write a script on my own :P

I have this simple question, it's more like a HTML question, but I figured i should post my question here anyway.

I have a form for users to fill out. one of the form field is asking users to input the date available for one job.

I have something like that for my mysql table:

Code: Select all

create table job (
....
date_available DATE,
....
)
This is how part of my form looks like for now :

Code: Select all

print "Date Available:<input type="text" name="date_available">
Now I was hoping to use drop down list for date instead of having the user to type in manually.
  • Does anybody have any suggestion on making this work?
  • How does drop down list pass the variables?
Thank you all.
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post by Johnm »

Are there specific dates available to the user to enter for a job? By this I mean are there only certain dates that will be valid such as only days of the month that fall on Monday through Friday? Will you be eliminating holidays as valid entries? How far into the future will the user be able to look for dates? 1 week? 3weeks? 3 months? Or will the current date be the only valid date (Probably not the case)?

Direwolf
cooler75
Forum Commoner
Posts: 40
Joined: Wed May 29, 2002 2:43 pm
Location: RichIsland

Post by cooler75 »

Hi, thanks for your reply


Example for what i am doing will be like this:

I am the employer (user), I am posting a job, now in the Date Available field, i would put in date when I need this position to start, ex. would be 05-31-2002.

My question is how do I make sure that the date can be entered into the form and print out like my date format (05-31-2002), so all date inputed will be consistent?

My solution is that I will have drop down list for my form, there will be 3 fields to input, one is day, one is month, one is year. Day will be number 1-31, month will be 1-12, year will be 2002 -2003, something like that. But how do i do that?

Or if you have better suggestion , please let me know..

thanks again
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post by Johnm »

Well,
I have everything written to do this and for the same purpose, putting the beginning production date on an order entry form. Seeing how the company I work for normally works Mon. - Fri. we decided to produce a dropdown menu for sales to add the beginning production date to the form only allowing valid dates to be used. On the exception (the shop works Saturday.. etc.) we allowed an override button so that with a password, a user could actually change the date to one not allowed in the option box. We wrote a database insert program in the C programming language and populated a table in the database with all the valid production dates for the next few years eliminating weekends and such. The web page in PHP only shows available beginning production dates that are valid.
Am I on the right track here??? Is this the type of thing you are trying to do?

If you do not care about which dates are shown, I also can help with that.
Direwolf
cooler75
Forum Commoner
Posts: 40
Joined: Wed May 29, 2002 2:43 pm
Location: RichIsland

Post by cooler75 »

Yours sound more complicated.

The script i am doing right now is a simple one, I dont really care what day, month, year the user needs the job to start, it's all depend on the user(employer), he can put down the start date (date available) on saturday or sunday, it doesnt matter. Basically, Date Available is the date telling those job-hunters when the job is available.

I have something like that in my mysql table:

date_available DATE,

So, in order to print date_available properly to show the user(job-hunters), what do I have to do with my form? Drop down menu? Have the users to input date manually?

I have trying to look around online for solution on how to deal with this, but i guess i am out of luck.

I hope I explained this good enough
thank you.
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post by Johnm »

Here is a very basic solution. Will this do it for you?

Code: Select all

<tr>
    <td align="left"><font size="2">
    &nbsp;Month</font></td>
    <td align="right"><font size="2"> 
    <select name="month">
    <?
        for ($i = 1; $i <= 12; $i++)
        &#123;
            echo "<option value="$i">$i\n";
        &#125;
    ?>
    </select>
    </font></td>
</tr>

<tr>
    <td align="left"><font size="2">
    &nbsp;Day</font></td>
    <td align="right"><font size="2">
    <select name="day">
    <? 
        for ($i = 1; $i <= 31; $i++)
        &#123;
            echo "<option value="$i">$i\n";
        &#125;
    ?>
    </select>
    </font></td>
</tr>
						
<tr>
    <td align="left"><font size="2">
    &nbsp;Year</font></td>
    <td align="right"><font size="2">
    <select name="year">
    <?
        for ($i = 2; $i <= 9; $i++)
        &#123;
            echo "<option value=200".$i.">200".$i."\n";
        &#125;
     ?>
	</select>
    </font></td>
</tr>

<?
    // Concantonate vars into month-day-year format 
    // for submission to database.
    $date_available=$month."-".$day."-".$year."\n";
?>
cooler75
Forum Commoner
Posts: 40
Joined: Wed May 29, 2002 2:43 pm
Location: RichIsland

Post by cooler75 »

Thanks, this is exactly the form i have been looking for.
however, $date_available doesnt print out anything

this is part of my script:

Code: Select all

<?
....

if ($action=="adding")
&#123;
$dberror = "";

$query = "INSERT INTO job (date_available)
         values ('$date_available')";
  
if (!mysql_query ($query, $link) )
&#123;
die (mysql_error());
&#125;
        
$date_available=$month."-".$day."-".$year."\n";
        
Print "Your listing has been added...";
&#125;

elseif ($action == "addjob")

print "<form name="addjob" action="./addjob.php?action=adding" method=post>";

....
print "<tr><td  width=30% align=left><font face="Verdana" size=2>Date Available:</td><td width=70% align=left>";
            print "<table><tr>";
            Print "<td align=left><font size=1>&nbsp;Month</font></td>";
            Print "<td align=right><font size=2><SELECT NAME=month >";
            for ($i = 1; $i <= 12; $i++)
            &#123;
            echo "<option value="$i">$i\n";
            &#125;
            print "</select></td>";
            Print "<td align=left><font size=1>&nbsp;Day</font></td>";
            Print "<td align=right><font size=2><SELECT NAME=day >";
            for ($i = 1; $i <= 31; $i++)
            &#123;
            echo "<option value="$i">$i\n";
            &#125;
            print "</select></td>";
            Print "<td align=left><font size=1>&nbsp;Year</font></td>";
            Print "<td align=right><font size=2><SELECT NAME=year >";
            for ($i = 2; $i <= 9; $i++)
            &#123;
            echo "<option value=200".$i.">200".$i."\n";
            &#125;
            print "</select></td>";


            Print "</tr></table>";
            Print "</td></tr>";
...

print "<input type=submit value=Submit Listing></form>";
... means there is something more.

When I try to pull the date from the database, it's only showing 0000-00-00

Could you tell what's wrong?
Thanks for your patient.
User avatar
gotDNS
Forum Contributor
Posts: 217
Joined: Tue May 07, 2002 5:53 pm
Location: West Chester, PA

Post by gotDNS »

maybe i can help, if i understand your question correctly.

You want to pass on variables from a selection list...?

For that, you'd do something like this:

Code: Select all

<select name="sorttype">
<option value="fname">Image Name</option>
<option value="fres">Image Dimensions</option>
<option value="fsize">File Size</option>
<option value="ftime">Upload Date</option>
</select>
Then in the php script:

Code: Select all

<?php
if($sorttype == "fname") &#123; echo "File name"; &#125;
else if($sorttype == "fres") &#123; echo "File resolution"; &#125;
else if($sorttype == "fsize") &#123; echo "File size"; &#125;
else if($sorttype == "ftime") &#123; echo "First time"; &#125;
?>
If that's what you mean, that should do it.
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post by Johnm »

I think all that you need to do is to add this:

Code: Select all

echo "<input type=hidden name=date_available  
          value=$date_available>\n";
That should take care of it.

Direwolf
Post Reply