Jump to content

how select data from table and place it in html form


doforumda

Recommended Posts

how can we select date of birth from db and break it into three variables so year stores in $year month stores in $month and day stores in $day. i need this because i have a form with three select menus so when user clicks edit to edit his date of birth then it select dob from db put the current dob in those select menus. my form is below

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
session_start();
include("dbconnect.php");
$query = mysql_query("SELECT * FROM dob WHERE userid='$_SESSION[userid]'");
while($row = mysql_fetch_assoc($query)) {
$date = $row['dob'];
?>
<form id="form1" name="form1" method="post" action="">
  Date of Birth: 
  <select name="month" id="month">
    <option value="Jan" SELECTED>Jan</option>
    <option value="Feb" >Feb</option>
    <option value="Mar" >Mar</option>
    <option value="Apr" >Apr</option>
  </select>
  <select name="day" id="day">
    <option value="1" selected>1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
  </select>
  <select name="year" id="year">
    <option value="2010" selected>2010</option>
    <option value="2009">2009</option>
    <option value="2008">2008</option>
  </select>
</form>
</body>
</html>

Link to comment
Share on other sites

[ot]Why do you have a table of it's own for dob? Do you expect people to have multiple dob's? (Just Curious)[/ot]

 

You need to provide us with more information, such as what data type is dob, is it a UNIX Timestamp, or a MySQL Date field? As this is needed to provide you with the correct answer.

Link to comment
Share on other sites

[ot]Why do you have a table of it's own for dob? Do you expect people to have multiple dob's? (Just Curious)[/ot]

 

You need to provide us with more information, such as what data type is dob, is it a UNIX Timestamp, or a MySQL Date field? As this is needed to provide you with the correct answer.

it is DATE field

Link to comment
Share on other sites

hi I am trying below code but it is not displaying date from database in select menus. the format of the date in mysql table is DATE here the value is 2008-04-04.

 

code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
//session_start();
include("dbConnect.php");
$query = mysql_query("SELECT * FROM basicinfo_age WHERE userid='1'");
while($row = mysql_fetch_assoc($query)) {
   $date = $row['dob'];
   //echo $date;
list($year, $month, $day) = explode("-", $date);
//$years = $year;
//$months = $month;
//$days = $day;
//echo $years;
}
?>
<form id="form1" name="form1" method="post" action="">
  Date of Birth:
  <select name="month" id="month">
    <option value="Jan" <?php if($month=="Jan") { echo "SELECTED"; } ?>>Jan</option>
    <option value="Feb" <?php if($month=="Feb") { echo "SELECTED"; } ?>>Feb</option>
    <option value="Mar" <?php if($month=="Mar") { echo "SELECTED"; } ?>>Mar</option>
    <option value="Apr" <?php if($month=="Apr") { echo "SELECTED"; } ?>>Apr</option>
  </select>
  <select name="day" id="day">
    <option value="1" <?php if($day=="1") { echo "SELECTED"; } ?>>1</option>
    <option value="2" <?php if($day=="2") { echo "SELECTED"; } ?>>2</option>
    <option value="3" <?php if($day=="3") { echo "SELECTED"; } ?>>3</option>
    <option value="4" <?php if($day=="4") { echo "SELECTED"; } ?>>4</option>
  </select>
  <select name="year" id="year">
    <option value="2010" <?php if($year=="2010") { echo "SELECTED"; } ?>>2010</option>
    <option value="2009" <?php if($year=="2009") { echo "SELECTED"; } ?>>2009</option>
    <option value="2008" <?php if($year=="2008") { echo "SELECTED"; } ?>>2008</option>
  </select>
</form>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.