Page 1 of 1
Form, Date question
Posted: Tue Jun 04, 2002 11:26 am
by cooler75
Hi,
I am learning to write a script on my own
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.
Posted: Tue Jun 04, 2002 11:48 am
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
Posted: Tue Jun 04, 2002 12:10 pm
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
Posted: Tue Jun 04, 2002 12:38 pm
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
Posted: Tue Jun 04, 2002 12:55 pm
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.
Posted: Tue Jun 04, 2002 2:14 pm
by Johnm
Here is a very basic solution. Will this do it for you?
Code: Select all
<tr>
<td align="left"><font size="2">
Month</font></td>
<td align="right"><font size="2">
<select name="month">
<?
for ($i = 1; $i <= 12; $i++)
{
echo "<option value="$i">$i\n";
}
?>
</select>
</font></td>
</tr>
<tr>
<td align="left"><font size="2">
Day</font></td>
<td align="right"><font size="2">
<select name="day">
<?
for ($i = 1; $i <= 31; $i++)
{
echo "<option value="$i">$i\n";
}
?>
</select>
</font></td>
</tr>
<tr>
<td align="left"><font size="2">
Year</font></td>
<td align="right"><font size="2">
<select name="year">
<?
for ($i = 2; $i <= 9; $i++)
{
echo "<option value=200".$i.">200".$i."\n";
}
?>
</select>
</font></td>
</tr>
<?
// Concantonate vars into month-day-year format
// for submission to database.
$date_available=$month."-".$day."-".$year."\n";
?>
Posted: Tue Jun 04, 2002 3:29 pm
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")
{
$dberror = "";
$query = "INSERT INTO job (date_available)
values ('$date_available')";
if (!mysql_query ($query, $link) )
{
die (mysql_error());
}
$date_available=$month."-".$day."-".$year."\n";
Print "Your listing has been added...";
}
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> Month</font></td>";
Print "<td align=right><font size=2><SELECT NAME=month >";
for ($i = 1; $i <= 12; $i++)
{
echo "<option value="$i">$i\n";
}
print "</select></td>";
Print "<td align=left><font size=1> Day</font></td>";
Print "<td align=right><font size=2><SELECT NAME=day >";
for ($i = 1; $i <= 31; $i++)
{
echo "<option value="$i">$i\n";
}
print "</select></td>";
Print "<td align=left><font size=1> Year</font></td>";
Print "<td align=right><font size=2><SELECT NAME=year >";
for ($i = 2; $i <= 9; $i++)
{
echo "<option value=200".$i.">200".$i."\n";
}
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.
Posted: Tue Jun 04, 2002 4:43 pm
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") { echo "File name"; }
else if($sorttype == "fres") { echo "File resolution"; }
else if($sorttype == "fsize") { echo "File size"; }
else if($sorttype == "ftime") { echo "First time"; }
?>
If that's what you mean, that should do it.
Posted: Wed Jun 05, 2002 9:15 am
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