drop_down menu options help
01-22-2007, 12:48 PM
|
drop_down menu options help
|
Posts: 157
Location: Toronto, CANADA
|
I have a form with a drop down menu:
HTML Code:
<select name="date" id="date">
<option selected>Select a Date</option>
<?
if ( $date == 'January 10' )
echo '<option value="January 10">January 10</option>' ;
?>
<option value="January 11">January 11</option>
<option value="January 12">January 12</option>
<option value="January 13">January 13</option>
<option value="January 16">January 16</option>
<option value="January 17">January 17</option>
<option value="January 23">January 23</option>
<option value="January 24">January 24</option>
<option value="January 25">January 25</option>
<option value="January 26">January 26</option>
<option value="January 31">January 31</option>
<option value="February 1">February 1</option>
<option value="February 2">February 2</option>
<option value="February 3">February 3</option>
<option value="February 6">February 6</option>
<option value="February 7">February 7</option>
<option value="February 9">February 9</option>
</select>
What I need to happen is for example if someone submits "January 10" to a table, the next time the page is loaded the option "January 10" isnt available anymore. As you can see I have attempted this with a php code but this hasnt worked out for me. I would appreciate some help on this.
Thanks! 
|
|
|
|
01-22-2007, 01:12 PM
|
Re: drop_down menu options help
|
Posts: 483
|
How have you defined $date? You probably want to use $_GET['date'] or $_POST['date'] instead.
|
|
|
|
01-22-2007, 01:26 PM
|
Re: drop_down menu options help
|
Posts: 157
Location: Toronto, CANADA
|
I already have it set as _POST:
PHP Code:
$date=$_POST['date'];
I don't want it to be an option in the pulldown if it has already been submitted.

|
|
|
|
01-22-2007, 01:28 PM
|
Re: drop_down menu options help
|
Posts: 157
Location: Toronto, CANADA
|
I also tryed using _GET and still not working
|
|
|
|
01-22-2007, 02:29 PM
|
Re: drop_down menu options help
|
Posts: 483
|
Oops. Are you sure you don't mean:
( $date != 'January 10' )
instead of:
( $date == 'January 10' )
?
|
|
|
|
01-22-2007, 03:34 PM
|
Re: drop_down menu options help
|
Posts: 483
|
That may be because I didn't say to use '='... I said '!='.
Basically what you're after is "if date doesn't equal 'Jan 10', add 'Jan 10'. The "!=" is essentially your "doesn't equal'.
|
|
|
|
01-22-2007, 03:40 PM
|
Re: drop_down menu options help
|
Posts: 157
Location: Toronto, CANADA
|
I apologize for not clarifying.  I did try that option already and I still get the same result.
|
|
|
|
01-22-2007, 03:48 PM
|
Re: drop_down menu options help
|
Posts: 483
|
OK, now I'm confused... the date has been submitted on a different page? I was under the impression that you were basically going from one page back to itself and removing the selected date from the list.
I have to assume, then, that the date in your results page is in a DB or something? You probably need to compare against that as opposed to using a GET or POST variable.... Either that, or I'm totally confused.
How about posting up the complete source for both of those pages?
|
|
|
|
01-22-2007, 03:54 PM
|
Re: drop_down menu options help
|
Posts: 157
Location: Toronto, CANADA
|
Sorry for the confusion TwistMyArm.
Here is the form page:
PHP Code:
<?
$username="*****";
$password="*****";
$database="students";
$name=$_POST['name'];
$name2=$_POST['name2'];
$dept=$_POST['dept'];
$ext=$_POST['ext'];
$date=$_GET['date'];
$time=$_POST['time'];
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
?>
<HTML>
<HEAD><TITLE>Partners Compensation Interviews 2006</TITLE>
<style type="text/css">
h1 {
font-family: arial;
font-size: 18pt;
color: #426085;
}
h2 {
font-family: arial;
font-size: 14pt;
color: #426085;
}
td {
font-family: arial;
font-size: 10pt;
}
body {
font-family: arial;
font-size: 10pt;
}.style1 {color: #333333}
</style></HEAD>
<BODY LEFTMARGIN="20" TOPMARGIN="20" RIGHTMARGIN="0" BOTTOMMARGIN="0" LINK="#3D007E" VLINK="#3D007E">
<CENTER>
<H1>Partners Compensation Interviews 2006 </H1>
<table width="600" border="0" cellspacing="0" cellpadding="15">
<tr>
<td><strong>Please click on the approprate date below and then select one of the avaiable sessions for that day. When finished, click on the "submit" button below. Note that all sessions are scheduled for the 37 NW boardroom unless otherwise indicated. </strong></td>
</tr>
</table>
<FORM ACTION="option2.php" METHOD="post">
<TABLE WIDTH="500" BORDER="0">
<TR>
<TD WIDTH="200" ALIGN="RIGHT" valign="middle">First Name : </TD>
<TD WIDTH="10" valign="middle"> </TD>
<TD WIDTH="290" valign="middle"><INPUT NAME="name" TYPE="text" id="name" SIZE=20></TD></TR>
<TR>
<TD ALIGN="RIGHT" valign="middle"> Last Name : </TD>
<TD valign="middle"> </TD>
<TD valign="middle"><INPUT NAME="name2" TYPE="text" id="name" SIZE=20></TD>
</TR>
<TR>
<TD ALIGN="RIGHT" valign="middle">Department : </TD>
<TD valign="middle"> </TD>
<TD valign="middle"><INPUT NAME="dept" TYPE="text" id="name" SIZE=20></TD>
</TR>
<TR>
<TD ALIGN="RIGHT" valign="middle">Extension : </TD>
<TD valign="middle"> </TD>
<TD valign="middle"><INPUT NAME="ext" TYPE="text" id="name" SIZE=20></TD>
</TR>
<TR>
<TD ALIGN="RIGHT" valign="middle">Session Date :</TD>
<TD valign="middle"> </TD>
<TD valign="middle"><select name="date" id="date">
<option selected>Select a Date</option>
<?
if ( $date = 'January 10' )
echo '<option value="January 10">January 10</option>' ;
?>
<option value="January 11">January 11</option>
<option value="January 12">January 12</option>
<option value="January 13">January 13</option>
<option value="January 16">January 16</option>
<option value="January 17">January 17</option>
<option value="January 23">January 23</option>
<option value="January 24">January 24</option>
<option value="January 25">January 25</option>
<option value="January 26">January 26</option>
<option value="January 31">January 31</option>
<option value="February 1">February 1</option>
<option value="February 2">February 2</option>
<option value="February 3">February 3</option>
<option value="February 6">February 6</option>
<option value="February 7">February 7</option>
<option value="February 9">February 9</option>
</select></TD>
</TR>
<TR>
<TD ALIGN="RIGHT" valign="middle">Session Time : </TD>
<TD valign="middle"> </TD>
<TD valign="middle"><label>
<select name="time" id="time">
<option>Select a Time</option>
<option value="8:00 am">8:00 am</option>
<option value="8:45 am">8:45 am</option>
<option value="9:30 am">9:30 am</option>
<option value="10:15 am">10:15 am</option>
<option value="11:00 am">11:00 am</option>
<option value="2:00 pm">2:00 pm</option>
<option value="2:45 pm">2:45 pm</option>
<option value="3:30 pm">3:30 pm</option>
<option value="4:15 pm">4:15 pm</option>
<option value="5:00 pm">5:00 pm</option>
<option value="5:45 pm">5:45 pm</option>
</select>
</label></TD>
</TR>
</TABLE>
<br>
<BR><INPUT TYPE="submit" VALUE="submit">
</FORM>
</CENTER>
</BODY>
</HTML>
And here is the page submitting to:
PHP Code:
<?
$username="xxxxxx";
$password="xxxxxx";
$database="xxxxxx";
$name=$_POST['name'];
$name2=$_POST['name2'];
$dept=$_POST['dept'];
$ext=$_POST['ext'];
$date=$_POST['date'];
$time=$_POST['time'];
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$DoubleCheck = "SELECT * FROM interview WHERE date='$date' AND time='$time'";
$result=mysql_query($DoubleCheck);
$num=mysql_numrows($result);
if (0==$num) {
$query = "INSERT INTO interview (name, name2, dept, ext, date, time) VALUES ('$name','$name2','$dept','$ext','$date','$time')";
mysql_query($query);
}
else{
echo "The date and time you selected is already taken.<br>Please click the <b>BACK</b> button and select a different time.<br></br><br>Contact Meg Lategan at <b>ext. 2167</b> if you are having trouble booking an available appointment.";
mysql_close();
exit;
}
$URL = "http://invites.fasken.com/interview/thanks.html";
header ("Location: $URL");
mail("djarrett@tor.fasken.com", "Interview Submission Made", "remove item");
?>
Last edited by Daman; 01-31-2007 at 07:09 AM..
|
|
|
|
01-22-2007, 06:39 PM
|
Re: drop_down menu options help
|
Posts: 483
|
Hmmm... so how do you access the form page? I'm going to assume that you access it via just a normal URL call (as in, no actual parameters) and so your problem is that you're not actually passing the date in.
Also, you can't mix GET and POST.
So I guess the big question is: how do you access the form in the first place? BTW, not that it really matters, but your username and password are showing in the second chunk of code 
|
|
|
|
01-22-2007, 10:22 PM
|
Re: drop_down menu options help
|
Posts: 157
Location: Toronto, CANADA
|
Yes I do access the form via a URL call:
http://invites.fasken.com/interview/index.php
I have attempted GET and POST and still the problem remain.
As for the username and password I did that on purpose for the post only for the sake of privacy.
Have I coded everything properly because I have looked at this to many times?
Is there an alternative to acheiving this solution? If so I would really appreciate an example.
OR just keep troubleshooting this. 
|
|
|
|
01-22-2007, 10:30 PM
|
Re: drop_down menu options help
|
Posts: 486
Name: Matt
|
OK.. I am completely confused with what you want to do. Your PHP is way off. Let me re-design it.
EDIT: I can fix it.. But I still need an idea of what you want to do, and what the major problem is. I fixed one of your queries (number rows result set) and you also reversed the if statement that used the query result. Just let me know what you want this form to do, and the exact, precise problem. If it is you never want them to select the same date twice you need to enter that into the database (their IPB or login or whatever) or set a cookie which of course would be much less secure. You can use your file system as well.
Last edited by Mattmaul1992; 01-23-2007 at 05:36 PM..
|
|
|
|
01-22-2007, 11:15 PM
|
Re: drop_down menu options help
|
Posts: 157
Location: Toronto, CANADA
|
You are exactly right. I never want them to select the same date twice. I thought that was clear in my previous posts. My apologies  Thanks for your feedback. I look forward to seeing your solution.
When you say I need to enter this into the database what exactly do you mean? Is there a specific data type I should use for this feild if thats what you mean. Please explain?
Thanks
|
|
|
|
01-23-2007, 08:07 AM
|
Re: drop_down menu options help
|
Posts: 483
|
Daman: the reason the GET isn't working on the first page is because by accessing it as index.php, you aren't passing in any GET parameters. Hopefully that makes sense...
Instead of the GET, you will need to access the database in almost the same way that you do when you are writing the date in the second page (except, you'll be reading from the database to see if that date is already used).
Sorry I can't help you anymore, things have just got a lot more hectic for me in real life 
|
|
|
|
01-23-2007, 10:27 AM
|
Re: drop_down menu options help
|
Posts: 157
Location: Toronto, CANADA
|
Thanks TwistMyArm. Hopefully someone else will help me with this.
Mattmaul1992: I would still like to see your version when you are done. 
|
|
|
|
01-23-2007, 04:49 PM
|
Re: drop_down menu options help
|
Posts: 486
Name: Matt
|
Here we go -
PHP Code:
<? $username="You wish you knew"; $password="lol... no thanks"; $database="hm... i forgot";
$name=$_POST['name']; $name2=$_POST['name2']; $dept=$_POST['dept']; $ext=$_POST['ext']; $date=$_POST['date']; $time=$_POST['time'];
mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database");
$DoubleCheck = "SELECT * FROM interview WHERE date='$date' AND time='$time'"; $result = mysql_query($DoubleCheck) or die ('Error in query: ' mysql_error()); $num = mysql_num_rows($result);
if ($num==0) { $query = "INSERT INTO interview (name, name2, dept, ext, date, time) VALUES ('$name','$name2','$dept','$ext','$date','$time')"; mysql_query($query); } else { echo "The date and time you selected is already taken.<br>Please click the <b>BACK</b> button and select a different time.<br></br><br>Contact Meg Lategan at <b>ext. 2167</b> if you are having trouble booking an available appointment."; mysql_close(); exit; }
$URL = "http://invites.fasken.com/interview/thanks.html"; header ("Location: $URL");
mail("djarrett@tor.fasken.com", "Interview Submission Made", "remove item"); ?>
The main problem with this page is that you used the statement "mysql_numrows" exactly how i typed it, when it should of been "mysql_num_rows". Also this probably didn't have much to do with it but you had 0 == $variable. I think it's mainly preference, but from now on use $variable == value instead (so in this case $num == 0 or $num == '0')
Your third problem on the first page (sorry I put the 2nd page first; it just happened to be the first one I edited) is fixed here =
PHP Code:
<? $username="*****"; $password="*****"; $database="students";
$name=$_POST['name']; $name2=$_POST['name2']; $dept=$_POST['dept']; $ext=$_POST['ext']; $date=$_GET['date']; $time=$_POST['time'];
mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database");
?>
<HTML> <HEAD><TITLE>Partners Compensation Interviews 2006</TITLE> <style type="text/css"> h1 { font-family: arial; font-size: 18pt; color: #426085; } h2 { font-family: arial; font-size: 14pt; color: #426085; } td { font-family: arial; font-size: 10pt; } body { font-family: arial; font-size: 10pt; }.style1 {color: #333333} </style></HEAD>
<BODY LEFTMARGIN="20" TOPMARGIN="20" RIGHTMARGIN="0" BOTTOMMARGIN="0" LINK="#3D007E" VLINK="#3D007E"> <CENTER> <H1>Partners Compensation Interviews 2006 </H1> <table width="600" border="0" cellspacing="0" cellpadding="15"> <tr> <td><strong>Please click on the approprate date below and then select one of the avaiable sessions for that day. When finished, click on the "submit" button below. Note that all sessions are scheduled for the 37 NW boardroom unless otherwise indicated. </strong></td> </tr> </table> <FORM ACTION="option2.php" METHOD="post">
<TABLE WIDTH="500" BORDER="0"> <TR> <TD WIDTH="200" ALIGN="RIGHT" valign="middle">First Name : </TD> <TD WIDTH="10" valign="middle"> </TD> <TD WIDTH="290" valign="middle"><INPUT NAME="name" TYPE="text" id="name" SIZE=20></TD></TR> <TR> <TD ALIGN="RIGHT" valign="middle"> Last Name : </TD> <TD valign="middle"> </TD> <TD valign="middle"><INPUT NAME="name2" TYPE="text" id="name" SIZE=20></TD> </TR> <TR> <TD ALIGN="RIGHT" valign="middle">Department : </TD> <TD valign="middle"> </TD> <TD valign="middle"><INPUT NAME="dept" TYPE="text" id="name" SIZE=20></TD> </TR> <TR> <TD ALIGN="RIGHT" valign="middle">Extension : </TD> <TD valign="middle"> </TD> <TD valign="middle"><INPUT NAME="ext" TYPE="text" id="name" SIZE=20></TD> </TR> <TR> <TD ALIGN="RIGHT" valign="middle">Session Date :</TD> <TD valign="middle"> </TD> <TD valign="middle"><select name="date" id="date"> <option selected>Select a Date</option> <? if ( $date == 'January 10' ) echo '<option value="January 10">January 10</option>' ; ?> <option value="January 11">January 11</option> <option value="January 12">January 12</option> <option value="January 13">January 13</option> <option value="January 16">January 16</option> <option value="January 17">January 17</option> <option value="January 23">January 23</option> <option value="January 24">January 24</option> <option value="January 25">January 25</option> <option value="January 26">January 26</option> <option value="January 31">January 31</option> <option value="February 1">February 1</option> <option value="February 2">February 2</option> <option value="February 3">February 3</option> <option value="February 6">February 6</option> <option value="February 7">February 7</option> <option value="February 9">February 9</option> </select></TD> </TR> <TR> <TD ALIGN="RIGHT" valign="middle">Session Time : </TD> <TD valign="middle"> </TD> <TD valign="middle"><label> <select name="time" id="time"> <option>Select a Time</option> <option value="8:00 am">8:00 am</option> <option value="8:45 am">8:45 am</option> <option value="9:30 am">9:30 am</option> <option value="10:15 am">10:15 am</option> <option value="11:00 am">11:00 am</option> <option value="2:00 pm">2:00 pm</option> <option value="2:45 pm">2:45 pm</option> <option value="3:30 pm">3:30 pm</option> <option value="4:15 pm">4:15 pm</option> <option value="5:00 pm">5:00 pm</option> <option value="5:45 pm">5:45 pm</option> </select> </label></TD> </TR> </TABLE> <br> <BR><INPUT TYPE="submit" VALUE="submit"> </FORM>
</CENTER>
</BODY> </HTML>
The problem here was that in your if statement you used only one '=' sign. That declares a variable. You want '==' which tests a variable with another statement.
Well, I'm used to fixing scripts by actually having them there in front of me on a server so this might not completely do it, but it did fix 3 errors. Remember to edit the database variables with your real information and also maybe not use variables for your database information because it is all to possible for someone to call on those variables. Secure your forms with !ereg/if statements on submission before sending them. That is a huge security issue as you'll see as you get farther into PHP.
Also on a last, most important note do you realize you included your database information on your post above there? Someone could drop all of your work on this project, and all other projects that you use that database for in 3 minutes right now. Good thing no one here's like that. Right?
Hope this helps
Last edited by Mattmaul1992; 01-23-2007 at 05:52 PM..
|
|
|
|
01-23-2007, 06:48 PM
|
Re: drop_down menu options help
|
Posts: 157
Location: Toronto, CANADA
|
Thanks Mattmaul1992, but it still doesnt work.  I am on a really tight deadline for tommorrow and this still is not working. Are you for hire? I'll wire you payment via Paypal ASAP if you can do this for me. What do you say?  Please help
Cheers
|
|
|
|
01-23-2007, 07:33 PM
|
Re: drop_down menu options help
|
Posts: 486
Name: Matt
|
Yes, I will help. You can e-mail me at matt@runeconnect.com and we can get started. Or just PM me. I am on for the next 6 hours so I'll have it ready tonight. Although after I'm able to run the script and then test it, I should be done within minutes.
Last edited by Mattmaul1992; 01-23-2007 at 07:42 PM..
|
|
|
|
01-29-2007, 01:13 PM
|
Re: drop_down menu options help
|
Posts: 157
Location: Toronto, CANADA
|
I just realized that there were quote in the html with out a backlash before for proper php syntax.  Proplem solved 
|
|
|
|
|
« Reply to drop_down menu options help
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|