Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PhP Form question / help!
Old 10-17-2007, 12:09 PM PhP Form question / help!
Junior Talker

Posts: 1
Trades: 0
Hey all!

Im trying to integrate a simple event calander into my phpbb forums that adds events to current and upcoming weeks in a database. The form I use has a text box for an event name with a submit button and two select menus:
1. a list of (upcoming) event weeks (running Sat through Fri) populated from a database where people have actually submitted an availability sometime in that week.
2. A list of specific days to select.

The php file calls itself from the a .tpl file handling the form and checks if the Post Method was used. The idea here is the first visit to the page defaults to the current week and the current day. If another week or day is selected and an event name is submitted, then the event is created in a database.

The database lookups are all correct and I can actually choose a new week from the week select menu and a different day from the day select menu and successfully add an event into the events database on the correct week/day.

The problem is the select boxes always revert back to the initial current week and today's day (Monday, Tue, etc...) instead of keeping the selected values from the form...even though I repopulate the array sent back to the form template with the values selected.

Any idea why it wont repopulate the form with the new selected data?

Here is the php code snippet:

Code:
 
if ($_SERVER['REQUEST_METHOD'] != 'POST')
{
  $today = getdate();
  if($today['wday'] == 6)
  { 
   $week= time();
  }
  else{
   $week= strtotime("last Saturday", time());
  }
  $day= date('D',time());
  $daylong = date('l',time());
      $sql = "SELECT DISTINCT`week` FROM `e_avail` WHERE `week` >= '$week' ORDER BY `week`";
        if ( !($result=$db->sql_query($sql)))
           {}
              while( $row = $db->sql_fetchrow($result) )
              { 
                $start = date('n/j/Y',$row['week']);
                $end = date('n/j/Y',(strtotime("+6 days",$row['week']))); 
                $weekstr = '<option value="'.$row['week'].'">'.$start.' through '.$end.'</option>';
                $template->assign_block_vars('menu_weeks',array( 'R_MENUWEEK' => $weekstr));
              }
      $db->sql_freeresult($result); 
      $selectstr='<option SELECTED value="'.time().'">'.$daylong.'</option>';
      $template->assign_block_vars('menu_days',array( 'R_MENUDAY' => $selectstr));
      for($n =1; $n <=6; $n +=1)
      {
        $nextday = time() +($n*24*60*60);
        $longday = date('l',$nextday);
        $daystr = '<option value="'.$nextday.'">'.$longday.'</option>';
        $template->assign_block_vars('menu_days',array( 'R_MENUDAY' => $daystr));
      }           
}
 
else
{
   $week=$_POST['week'];
   $day= date('D',$_POST['day']);
   $longday = date('l',$POST['day']);
   $event=$_POST['event'];
 
      $sql = "SELECT DISTINCT `week` FROM `e_avail` WHERE `week` >= '$week' ORDER BY `week`";
        if ( !($result=$db->sql_query($sql)))
          {}
              while( $row = $db->sql_fetchrow($result) )
              { 
                $start = date('n/j/Y',$row['week']);
                $end = date('n/j/Y',(strtotime("+6 days",$row['week']))); 
                $weekstr = '<option value="'.$row['week'].'">'.$start.' through '.$end.'</option>';
                $template->assign_block_vars('menu_weeks',array( 'R_MENUWEEK' => $weekstr));
              }
      $db->sql_freeresult($result); 
 
      $selectstr='<option SELECTED value="'.$_POST['day'].'">'.$longday.'</option>';
      $template->assign_block_vars('menu_days',array( 'R_MENUDAY' => $selectstr));
      for($n =1; $n <=6; $n +=1)
      {
        $nextday = $POST['day'] +($n*24*60*60);
        $longday = date('l',$nextday);
        $daystr = '<option value="'.$nextday.'">'.$longday.'</option>';
        $template->assign_block_vars('menu_days',array( 'R_MENUDAY' => $daystr));
      }
 
   if(!($_POST['event']==''))
    {
      $sql  = "INSERT INTO " . _events . "(week,day,event_name) VALUES ('$week','$day','$event')";
            if (!$db->sql_query($sql))
    }
 
}


...and the actual form code in the template.
Code:
 
 
<table width="860">
 <form method="post" action="events.php" >
 <tr><td><br /> 
    <b>Week:  </b>
     <select name="week" style="background-color:#FFFFFF; color:#000000">
             <!-- BEGIN menu_weeks --> 
              {menu_weeks.R_MENUWEEK}
             <!-- END menu_weeks -->
            </select> 
     <br />Day: </b>
     <select name="day" style="background-color: #FFFFFF;color:#000000" >
              <!-- BEGIN menu_days --> 
              {menu_days.R_MENUDAY}
             <!-- END menu_days -->
            </select>
            <br />Create Event:</b>
      <input type=text name="event" style="background-color: #FFFFFF;color:#000000" size=20> 
                    <input type=submit style="background-color: #FFFFFF;color:#000000" value="Create Event">
         </form>
         </td>
      </tr>
</table>
Thanks in advance!

Last edited by Quantum; 10-17-2007 at 12:12 PM..
Quantum is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to PhP Form question / help!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.09294 seconds with 12 queries