Post variables not sending

Discussion in 'PHP' started by j_o, Jun 8, 2011.

  1. #1
    Hi Everyone,

    I have a form that basically lets you select a specific date which I send using the post method. When I send it I get the error:
    where month is the post variable I am trying to call. This error comes up three times for each of the POST variables I am trying to call. Below is my code:

    The form:
    
    <form action="calendar.php?action=date" method="POST">
                            <h2>Choose a date:
                                        <?php
                                        $cal_set = list_calendar();
                                        $output = "<select>\n";
                                        while($calendar = mysql_fetch_array($cal_set)){
                                            $output .="<option name=\"month\" value=\"".$calendar['id']."\"";
                                            if ($calendar['id'] == $month){ 
                                                $output .= " selected=\"selected\"";
                                            }
                                            $output .= ">".$calendar['month']."</option>\n";
                                        }
                                        $output .= "</select>\n";
                                    
                                        $output .= "<select>\n";
                                        for ($i = 1; $i <= 31; $i++) {
                                            $output .="<option name=\"day\" value=\"".$i."\"";
                                            if ($i == $day){ 
                                                $output .= " selected=\"selected\"";
                                            }										
                                            $output .=">".$i."</option>\n";
                                        }
                                        $output .= " </select>\n";
                                        $output .= "<select>\n";
                                        for ($i = 0; $i <= 1; $i++) {
                                            $output .= "<option name=\"year\" value=\"".(date("Y")+$i)."\"";
                                            if ((date("Y")+$i) == $year){ 
                                                $output .= " selected=\"selected\"";
                                            }
                                            $output .= ">".(date("Y")+$i)."</option>\n";
                                        }
                                        $output .= "</select>\n";
                                        echo $output;
                                        ?>
                                        <input type="submit" value="Go" name="ToDate" /></h2>
                                </form>
    
    PHP:

    The code where I check if the form has been submitted is at the top of the page:

    
    <?php
        require_once('includes\connection.php');
        require_once('includes\functions.php');
        $public = TRUE;
    
         if (isset($_POST['ToDate'])){
            $month = $_POST['month'];
            $day = $_POST['day'];
            $year = $_POST['year'];
            die("DONE");
         }else{
            $month = date("n");
            $day = date("j");
            $year = date("Y");
         }
         $timestamp = create_timestamp($month, $day, $year);
    ?>
    
    PHP:
    Any help is appreciated. Thanks in advance!
     
    Last edited: Jun 8, 2011
    j_o, Jun 8, 2011 IP
  2. techbongo

    techbongo Active Member

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    80
    #2
    It's because there is no such index called 'month', in $_POST array. Please re-check your HTML Form Code. You don't have an input field defined with name="month". 'name' is a valid attribute of <select> tag, not the <option> tag. So change form code as follows:

    
    <form action="calendar.php?action=date" method="POST">
                            <h2>Choose a date:
                                        <?php
                                        $cal_set = list_calendar();
                                        $output = "<select name=\"month\">\n";
                                        while($calendar = mysql_fetch_array($cal_set)){
                                            $output .="<option value=\"".$calendar['id']."\"";
                                            if ($calendar['id'] == $month){ 
                                                $output .= " selected=\"selected\"";
                                            }
                                            $output .= ">".$calendar['month']."</option>\n";
                                        }
                                        $output .= "</select>\n";
                                    
                                        $output .= "<select name=\"day\">\n";
                                        for ($i = 1; $i <= 31; $i++) {
                                            $output .="<option value=\"".$i."\"";
                                            if ($i == $day){ 
                                                $output .= " selected=\"selected\"";
                                            }                                       
                                            $output .=">".$i."</option>\n";
                                        }
                                        $output .= " </select>\n";
                                        $output .= "<select name=\"year\">\n";
                                        for ($i = 0; $i <= 1; $i++) {
                                            $output .= "<option value=\"".(date("Y")+$i)."\"";
                                            if ((date("Y")+$i) == $year){ 
                                                $output .= " selected=\"selected\"";
                                            }
                                            $output .= ">".(date("Y")+$i)."</option>\n";
                                        }
                                        $output .= "</select>\n";
                                        echo $output;
                                        ?>
                                        <input type="submit" value="Go" name="ToDate" /></h2>
                                </form>
    
    
    HTML:
    Use this code and it'll work, I believe.
     
    techbongo, Jun 8, 2011 IP
    j_o likes this.
  3. j_o

    j_o Well-Known Member

    Messages:
    516
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    113
    #3
    Thanks a ton. I didn't even notice that. It works perfect now.
     
    j_o, Jun 8, 2011 IP