如何在一个字段中将三个下拉值插入数据库

时间:2014-10-10 06:27:17

标签: dropdownbox

如何在一个字段中插入三个下拉值到我的数据库中以插入出生日期。我是$ dob变量是不是没有?请帮帮我。

我的表单是

 <form name="" id="order-form" class="smart-form" role="form" action="" method="post" enctype="multipart/form-data">
 <tr>
  <td><font color="#334D66"> Date of Birth: </td>
  <td><select name="birthday">
      <option selected></option>
      <option>01</option>
      <option>02</option>
      .
      .
    </select>
    <select name="birthmonth">
      <option selected></option>
      <option>January</option>
      <option>February</option>
      .          
      .
    </select>
    <select name="birthyear">
      <option selected></option>
      <option>1999</option>
      <option>1998</option>
      .
      .
      </select>
  </td>
</tr>

和 我的插入代码是这样的

 <?php
if(isset($_POST['submit']))
{

$day=$_POST['birthday'];
$month=$_POST['birthmonth'];
$year=$_POST['birthyear'];
$dob = $day.'/'.$month.'/'.$year;

$data =array('username' => $_POST['username'],
            'firstname' => $_POST['firstname'],
            'lastname' => $_POST['lastname'],
            'email' => $_POST['email'],
            'homepage' => $_POST['homepage'],
            'adress' => $_POST['adress'],
            'city' => $_POST['city'],
            'province_id' => $_POST['province_id'],
            'postcode' => $_POST['postcode'],
            'country_id' => $_POST['country_id'],
            'phone' => $_POST['phone'],
            'dob' => $dob,
            'gender' => $_POST['gender'],
            'occupation' => $_POST['occupation'],
            'fav_quotes' => $_POST['fav_quotes'],
            'news' => $_POST['news'],
            'newsletter' => $_POST['newsletter'],
            'reg_type_id' => $reg_type_id,
            'images' => $_POST['images'] 
            );
insert('user', $data);
//echo "Success";
header("Location: paypal-invoice/createandsend.example.php");
}


?>

提前致谢。

1 个答案:

答案 0 :(得分:0)

你可以在mysql数据库中插入dob,因为mysql接受yyyy-mm-dd格式所以你应该

$year.'-'.$month.'-'.$day

我认为它适合你