
edfou
Members-
Posts
10 -
Joined
-
Last visited
edfou's Achievements

Newbie (1/5)
0
Reputation
-
Dropdown menu will not output pm only am values to table
edfou replied to edfou's topic in PHP Coding Help
Thanks jcbones and Barand. I'll close and mark this post as Solved and start a new one shortly as the topic has changed. Cheers Ed -
Dropdown menu will not output pm only am values to table
edfou replied to edfou's topic in PHP Coding Help
I pasted in a recent test record from my table below, however my challenge now is not so much the day or time data but the date_entered data and the expiry_date data (which needs to be set at 30 days later than the date_entered data). I can use NOW() in my INSERT into the table for date_entered but it is 2 hours ahead and I need to fix that. Thanks for following up!!! Ed id lostfound day time description location name contact 127 LOST 02/11/2013 0:00 10/11/2013 23:00 DF DF TESTING-25 AA date_entered expiry_date 0000-00-00 00:00:00 0000-00-00 00:00:00 -
Dropdown menu will not output pm only am values to table
edfou replied to edfou's topic in PHP Coding Help
Thanks for your help guys! I worked through that and got that part working. What I did is take the value as posted from the form and changed the format before it gets written to the table (see below). However I have a new challenge and that is simply to capture the current date/time but subtract two hours because my server is in a different timezone. I have added timezone code (see below) but that doesn't seem to help with this. The intent is to populate the POSTED column accurately. Then, eventually I hope to compare the value in the posted column with a later date so that old posts will get deleted automatically after 30 days. Not sure this is possible(!). Thanks! if ( isset ($_POST['submit'])) { date_default_timezone_set("America/Vancouver"); $day = date("Y-m-d H:i:s", strtotime($_POST['day'])); $time = date("Y-m-d H:i:s", strtotime($_POST['time'])); -
Hi guys, I'm having difficulty solving an issue with the time display. When I choose a time from the drop down on my form at http://www.cmfsc.ca/index.php?page=lostandfoundform it writes the time to my table in this format 09:00:00 and even though I choose 9pm in the form drop down menu, it always outputs am when I go to view the records page at http://www.cmfsc.ca/index.php?page=lostandfound_records Note; I don't want to use the 24 hr clock, and I think I should be able to use the 12hr clock with the am or pm suffix. Here is the relevant portion of my form code: <tr> <td>Time lost/found</td> <td> <select name="time"> <? print "<option value=\"\">choose</option>\n"; $startTime = mktime(7, 00, 0, 0, 0, 0); $endTime = mktime(23, 00, 0, 0, 0, 0); for ($i = $startTime; $i <= $endTime; $i = $i + 3600) { $thisTime = date('g:i a', $i); // nothing selected by default $selected = ''; // if the form is submitted. // Check that the posted value is the same as this value // if is the same set it to selected. if(isset($_POST['time']) && $_POST['time'] == $thisTime) $selected = ' selected'; // added the selected attribute here print "<option value=\"$thisTime\"$selected>$thisTime</option>\n"; } ?> </select> </td> </tr> And my query to INSERT into the table is : // Define the query. $query = "INSERT INTO lostandfound (id, lostfound, day, time, description, location, name, contact, date_entered) VALUES (0, '$lostfound', '$day', '$time', '".mysql_real_escape_string($description)."', '".mysql_real_escape_string($location)."', '".mysql_real_escape_string($name)."', '".mysql_real_escape_string($contact)."', NOW())"; And here is the relevant code portion for the records page: "\n\t<td>". $row['description'] . "</td>". "\n\t<td>". $row['location'] . "</td>". "\n\t<td>". $row['day'] . "</td>". "\n\t<td>". date('g:i a',strtotime($row['time'])) . "</td>". "\n\t<td>". $row['name'] . "</td>". "\n\t<td>". $row['contact'] . "</td>". "\n\t<td>". date('M-d', strtotime($row['date_entered'])) . "</td>"; print "</tr>"; Thanks for any help!!! Ed
-
Hi Barand, thanks a lot for the tip! I used that to touch up the code and it now works great. Code changes in bold below if anyone else can benefit from this too. Cheers Ed <td>Date lost/found *</td> <td><select name="day"> <? print "<option value=\"\">choose</option>\n"; date_default_timezone_set("America/Vancouver"); $startDay = mktime(); $endDay = mktime() - (14 * 24 * 3600); for ($i = $startDay; $i >= $endDay; $i = $i - 86400){ $thisDate = date('l F jS Y', $i); // nothing selected by default $selected = ''; // if the form is submitted. // Check that the posted value is the same as this value // if is the same set it to selected. if(isset($_POST['day']) && $_POST['day'] == $thisDate) $selected = ' selected'; // added the selected attribute here \/ print "<option value=\"$thisDate\"$selected>$thisDate</option>\n"; } ?> </select> </td> </tr> <tr> <td></td><td><? echo $err_day; ?></td> </tr>
-
Hi guys, I would really appreciate some help with this code. How it works now is that it creates a drop down menu for date starting today and for the last 14 days. There is also a time drop down menu. Both correctly retain the selected values if the page is refreshed. Now in addition I need the following to work: 1. have the word "choose" as the displayed default menu item instead of the initial date and initial time values that show now. 2. secondly if a value is NOT chosen from either menu (and after hitting Submit button) I want the error to display similar to if other required fields are not filled in. It seems that because the default menu value IS already a day value, the script thinks that there is already a POST from these menus and will therefore not display the error which checks for each menu POST. <? echo $err_day; ?> <? echo $err_time; ?> Here's my script online: http://www.cmfsc.ca/forms/lostandfound-WORKING.php Below is the relevant code that needs to be tweaked somehow. Thanks!!! Ed <tr> <td>Date lost/found *</td> <td><select name="day"> <? date_default_timezone_set("America/Vancouver"); $startDay = mktime(); $endDay = mktime() - (14 * 24 * 3600); for ($i = $startDay; $i >= $endDay; $i = $i - 86400) { $thisDate = date('l F jS Y', $i); // nothing selected by default $selected = ''; // if the form is submitted. // Check that the posted value is the same as this value // if is the same set it to selected. if(isset($_POST['day']) && $_POST['day'] == $thisDate) $selected = ' selected'; // added the selected attribute here \ / print "<option value=\"$thisDate\"$selected>$thisDate</option>\n"; } ?> </select> </td> </tr> <tr> <td>Time lost/found *</td> <td><select name="time"> <? $startTime = mktime(9, 00, 0, 0, 0, 0); $endTime = mktime(20, 00, 0, 0, 0, 0); for ($i = $startTime; $i <= $endTime; $i = $i + 1800) { $thisTime = date('g:i a', $i); // nothing selected by default $selected = ''; // if the form is submitted. // Check that the posted value is the same as this value // if is the same set it to selected. if(isset($_POST['time']) && $_POST['time'] == $thisTime) $selected = ' selected'; // added the selected attribute here print "<option value=\"$thisTime\"$selected>$thisTime</option>\n"; } ?> </select> </td> </tr>
-
radio button choice needs to control dropdown menu content
edfou replied to edfou's topic in PHP Coding Help
Hi Ch0cu3r I ran out of time and went with a simpler choice for my menu in the mean time. However I DO want to use the method you have kindly helped on. When I get time, I will try again to integrate your supplied code into my php page so that it will work. Thanks so much for all the help! Much appreciated to you and Barand. Cheers Ed -
radio button choice needs to control dropdown menu content
edfou replied to edfou's topic in PHP Coding Help
Thank you very much for the help! I see that the code works as I need it to when I place it into a new testing page as is and and click on either option. Here is the page http://www.cmfsc.ca/forms/FormsTesting4.php However I have a couple of problems; the option value is not retained (sticky) upon hitting the Submit button and secondly I'm having difficulty integrating it into my larger form (php page). http://www.cmfsc.ca/forms/referee_evaluation.php The first script portion I placed into the head section of the page. The supplied form code was placed into the existing form section, except I stripped out the <form action> row and the <input type="submit" row since I already have those in my existing form. The final script section was placed as is just before the closing body tag as it is in the example. I made the rows with bold titles so you can find on the page and test http://www.cmfsc.ca/forms/referee_evaluation.php Do you have any suggestions on those you difficulities? Many thanks! Ed -
I have a new form that has one drop down menu which needs to be dependent on the Gender choice immediately above it. I've never done this before and am having some trouble. Here's the form http://www.cmfsc.ca/forms/referee_evaluation.php At the moment I have separate require_once files that contain the array data and code to create each menu; one for male and one for female. Choosing the suitable require file is done as the page loads so of course it is ineffective as it is not dependent on the radio button output. if ($gender == 'M') { require_once("teams_male2013.php"); } else { require_once("teams_female2013.php"); } The only way I can seem to get it to work is to have the user scroll down and click the Submit button to reload the page so that the radio button choice can be applied to which menu gets populated! My question is: what options do I have to make the content of the menus dependent on a radio button choice? Can I use PHP to solve this? Do I have to apply javascript ? Is this what is called dynamic menus? Do I need to (or should I anyway) move the array data into my database instead of having it hardcoded in the require files? What is the best approach? Sorry for the basic questions! Thanks! Ed
-
Can view form here. Need to add sticky quality! http://www.cmfsc.ca/forms/FormsTesting.php Here's my code. How do I modify to add sticky quality, to retain values after Submitting form? <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post"> <? $startTime = mktime() - (2 * 3600); $endTime = mktime() - (14 * 24 * 3600); print '<select name="newgameday">'; for ($i = $startTime; $i >= $endTime; $i = $i - 86400) { $thisDate = date('l F jS Y', $i); print "<option value=\"$thisDate\">$thisDate</option>\n"; } print '</select>'; ?> <input type="submit" name="submit" value="Submit" /> </form> Thanks for any help!!