javascript月计算器不工作

时间:2014-11-05 10:15:51

标签: javascript php

我有以下代码。这是一个自动月生成器。如果我单击“提交”,则该值将存储为数据库中的 NOVEMBER 。但我希望将其保存为 11 。帮助我。

<?php 
    if(isset($_POST['Submit']))
    {
        $id=$_POST['id'];
        $month=$_POST['month'];
        $total=$_POST['total'];
        $points=$_POST['points'];
        $lotsize=$_POST['lotsize'];
        $amount=$_POST['amount'];

        $sql = 'INSERT INTO total(id,month,total,points,lotsize,amount) VALUES("'.$id.'","'.$month.'","'.$total.'","'.$points.'","'.$lotsize.'","'.$amount.'")';
        $msg="<p style=\"color:#3366FF; font-size:13px;\"> Successfull!</p>";
        if (!mysql_query($sql, $con))
        {
            die('Error: ' . mysql_error());
        }

        echo "<script type='text/javascript'>

        alert('Details Submitted');

        </script>";
    }
?>

<select id="month" name="month"><option value=""><?php echo date('F') ?></option>
    <option value="1">January</option><?php if($month == "january"){echo "checked";} ?>
    <option value="2">February</option><?php if($month == "february"){echo "checked";} ?>
    <option value="3">March</option><?php if($month == "march"){echo "checked";} ?>
    <option value="4">April</option><?php if($month == "april"){echo "checked";} ?>
    <option value="5">May</option><?php if($month == "may"){echo "checked";} ?>
    <option value="6">June</option><?php if($month == "june"){echo "checked";} ?>
    <option value="7">July</option><?php if($month == "july"){echo "checked";} ?>
    <option value="8">August</option><?php if($month == "august"){echo "checked";} ?>
    <option value="9">September</option><?php if($month == "september"){echo "checked";} ?>
    <option value="10">October</option><?php if($month == "october"){echo "checked";} ?>
    <option value="11">November</option><?php if($month == "November"){echo "checked";} ?>
    <option value="12">December</option><?php if($month == "december"){echo "checked";} ?>
</select>

1 个答案:

答案 0 :(得分:0)

我认为问题在于您的HTML代码,您正在使用checked,它应该用于复选框和单选按钮,而不是下拉菜单。

如果您希望if($month == "November")存储为$month,那么您使用的是if($month == "11")吗?

所以我相信你的最终代码如下:

<select id="month" name="month">
    <option value=""><?php echo date('F') ?></option>
    <option value="1" <?php if ($month == "1") echo 'selected' ?>>January</option>
    <option value="2" <?php if ($month == "2") echo 'selected' ?>>February</option>
    <option value="3" <?php if ($month == "3") echo 'selected' ?>>March</option>
    <option value="4" <?php if ($month == "4") echo 'selected' ?>>April</option>
    <option value="5" <?php if ($month == "5") echo 'selected' ?>>May</option>
    <option value="6" <?php if ($month == "6") echo 'selected' ?>>June</option>
    <option value="7" <?php if ($month == "7") echo 'selected' ?>>July</option>
    <option value="8" <?php if ($month == "8") echo 'selected' ?>>August</option>
    <option value="9" <?php if ($month == "9") echo 'selected' ?>>September</option>
    <option value="10" <?php if ($month == "10") echo 'selected' ?>>October</option>
    <option value="11" <?php if ($month == "11") echo 'selected' ?>>November</option>
    <option value="12" <?php if ($month == "12") echo 'selected' ?>>December</option>
</select>