...

View Full Version : enter my forms dob and gender into a db



runnerjp
02-21-2008, 05:08 PM
hey guys... i have this html.java code

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 Form</title>
<link rel="stylesheet" type="text/css" href="view.css" media="all">
<script type="text/javascript" src="view.js"></script>
<script type="text/javascript" src="calendar.js"></script>
</head>
<body id="main_body" >

<img id="top" src="top.png" alt="">
<div id="form_container">


<h1>&nbsp;</h1>
<form id="form_29490" class="appnitro" method="post" action="">
<div class="form_description">
<h2>&nbsp;</h2>
<p>&nbsp;</p>
</div>
<ul >

<li id="li_2" >

<label class="description" for="element_2">Drop Down </label>
<div>
<select class="element select medium" id="element_2" name="element_2">
<option value="" selected="selected"></option>
<option value="1" >Male</option>
<option value="2" >Female</option>

</select>
</div><p class="guidelines" id="guide_2"><small>Please pick you gender</small></p>
</li> <li id="li_1" >

<label class="description" for="element_1">Date </label>
<span>
<input id="element_1_1" name="element_1_1" class="element text" size="2" maxlength="2" value="" type="text"> /
<label for="element_1_1">MM</label>
</span>
<span>
<input id="element_1_2" name="element_1_2" class="element text" size="2" maxlength="2" value="" type="text"> /
<label for="element_1_2">DD</label>

</span>
<span>
<input id="element_1_3" name="element_1_3" class="element text" size="4" maxlength="4" value="" type="text">
<label for="element_1_3">YYYY</label>
</span>

<span id="calendar_1">
<img id="cal_img_1" class="datepicker" src="calendar.gif" alt="Pick a date.">
</span>
<script type="text/javascript">
Calendar.setup({
inputField : "element_1_3",
baseField : "element_1",
displayArea : "calendar_1",
button : "cal_img_1",
ifFormat : "&#37;B %e, %Y",
onSelect : selectDate
});
</script>

<p class="guidelines" id="guide_1"><small>Please enter your date of bith</small></p>
</li>

<li class="buttons">
<input type="hidden" name="form_id" value="29490" />

<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
</li>
</ul>
</form>
</body>
</html>


put how can i select data and add it to my database??

$query = "INSERT INTO users (idob, gender)
VALUES (Huh??)";

_Aerospace_Eng_
02-21-2008, 05:30 PM
You are jumping the gun here. First you need to know how to get the variables from the form using $_POST['input_name'];

Then you need to make sure the data is ran through mysql_real_escape_string. Once you do that you can create your sql statement. The values will be your php post variables. So...where is your php?

runnerjp
02-21-2008, 05:40 PM
ok will im not sure at ALL how to get users pull down collum and select into sql... i can do simple text fields
include("connect.php");
$dob = $_POST['dob'];
$about_me = $_POST['about_me'];
$events = $_POST['events'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];

$query = "INSERT INTO users (id, dob, about_me, events, first_name, last_name)
VALUES ('', '$dob', '$about_me', '$events', '$first_name', '$last_name')";

$results = mysql_query($query) or die
("Could not execute query : $query." . mysql_error());

if ($results)
{
echo "Details added.";
}
mysql_close();
?>

but i dont understand the whole menus and selection boxes?

_Aerospace_Eng_
02-21-2008, 05:50 PM
Its the same way as text boxes. The selected value of the select gets submitted throught $_POST

$gender = mysql_real_escape_string($_POST['element_2']);
For the DOB you need to concatenate all of the values

$year = intval($_POST['element_1_3']);
$month = intval($_POST['element_1_1']);
$day = intval($_POST['element_1_2']);
$dob = $year.'/'.$month.'/'.$day;
$query = "INSERT INTO users (dob, about_me, events, first_name, last_name)
VALUES (DATE('".$dob."'), '$about_me', '$events', '$first_name', '$last_name')";
I'm using the names of the inputs in the code you posted. You should leave off the id column if it gets auto incremented.

runnerjp
02-21-2008, 06:39 PM
would there be an easyer way to do dob?

_Aerospace_Eng_
02-21-2008, 06:43 PM
You could use a text box but then you would have to validate input to make sure its a valid date. It will get more complicated.

runnerjp
02-22-2008, 01:02 PM
humm its not going to plan lol i put in 1/jan/2004 to try it out and i get úday/0/0 outputted :S


<? <select id="day" name="DateOfBirth_Day">
<option> - Day - </option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>

<select id="date" name="DateOfBirth_Month">
<option> - Month - </option>
<option value="January">January</option>
<option value="Febuary">Febuary</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select>

<select id="year" name="DateOfBirth_Year">
<option> - Year - </option>
<option value="2004">2004</option>
<option value="2003">2003</option>
<option value="2002">2002</option>
<option value="2001">2001</option>
<option value="2000">2000</option>
<option value="1999">1999</option>
<option value="1998">1998</option>
<option value="1997">1997</option>
<option value="1996">1996</option>
<option value="1995">1995</option>
<option value="1994">1994</option>
<option value="1993">1993</option>
<option value="1992">1992</option>
<option value="1991">1991</option>
<option value="1990">1990</option>
<option value="1989">1989</option>
<option value="1988">1988</option>
<option value="1987">1987</option>
<option value="1986">1986</option>
<option value="1985">1985</option>
<option value="1984">1984</option>
<option value="1983">1983</option>
<option value="1982">1982</option>
<option value="1981">1981</option>
<option value="1980">1980</option>
<option value="1979">1979</option>
<option value="1978">1978</option>
<option value="1977">1977</option>
<option value="1976">1976</option>
<option value="1975">1975</option>
<option value="1974">1974</option>
<option value="1973">1973</option>
<option value="1972">1972</option>
<option value="1971">1971</option>
<option value="1970">1970</option>
<option value="1969">1969</option>
<option value="1968">1968</option>
<option value="1967">1967</option>
<option value="1966">1966</option>
<option value="1965">1965</option>
<option value="1964">1964</option>
<option value="1963">1963</option>
<option value="1962">1962</option>
<option value="1961">1961</option>
<option value="1960">1960</option>
<option value="1959">1959</option>
<option value="1958">1958</option>
<option value="1957">1957</option>
<option value="1956">1956</option>
<option value="1955">1955</option>
<option value="1954">1954</option>
<option value="1953">1953</option>
<option value="1952">1952</option>
<option value="1951">1951</option>
<option value="1950">1950</option>
<option value="1949">1949</option>
<option value="1948">1948</option>
<option value="1947">1947</option>
<option value="1946">1946</option>
<option value="1945">1945</option>
<option value="1944">1944</option>
<option value="1943">1943</option>
<option value="1942">1942</option>
<option value="1941">1941</option>
<option value="1940">1940</option>
<option value="1939">1939</option>
<option value="1938">1938</option>
<option value="1937">1937</option>
<option value="1936">1936</option>
<option value="1935">1935</option>
<option value="1934">1934</option>
<option value="1933">1933</option>
<option value="1932">1932</option>
<option value="1931">1931</option>
<option value="1930">1930</option>
<option value="1929">1929</option>
<option value="1928">1928</option>
<option value="1927">1927</option>
<option value="1926">1926</option>
<option value="1925">1925</option>
<option value="1924">1924</option>
<option value="1923">1923</option>
<option value="1922">1922</option>
<option value="1921">1921</option>
<option value="1920">1920</option>
<option value="1919">1919</option>
<option value="1918">1918</option>
<option value="1917">1917</option>
<option value="1916">1916</option>
<option value="1915">1915</option>
<option value="1914">1914</option>
<option value="1913">1913</option>
<option value="1912">1912</option>
<option value="1911">1911</option>
<option value="1910">1910</option>
<option value="1909">1909</option>
<option value="1908">1908</option>
<option value="1907">1907</option>
<option value="1906">1906</option>
<option value="1905">1905</option>
<option value="1904">1904</option>
<option value="1903">1903</option>
<option value="1902">1902</option>
<option value="1901">1901</option>
<option value="1900">1900</option>
</select> ?>

and update code


<?php $id = $_POST['id'];
$dob = $_POST['dob'];
$about_me = $_POST['about_me'];
$events = $_POST['events'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$gender = $_POST['gender'];
$year = intval($_POST['DateOfBirth_Year']);
$month = intval($_POST['DateOfBirth_Month']);
$day = intval($_POST['DateOfBirth_Day']);
$dob = úday.'/'.$month.'/'.$year;


$update = "UPDATE users SET dob='$dob', about_me = '$about_me', events = '$events', first_name = '$first_name', gender = '$gender', last_name = '$last_name' WHERE id='$id' ";
$rsUpdate = mysql_query($update);
if ($rsUpdate)
{
echo "Update successful.";
} mysql_close();
?>

abduraooft
02-22-2008, 01:19 PM
http://www.dynamicdrive.com/dynamicindex7/jasoncalendar.htm will give an easy way to get the date in any required format!

runnerjp
02-22-2008, 04:37 PM
Code:


<select id="day" class="input" name="DateOfBirth_Day">
<option value="<?php echo $day ?>">- Day - </option>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="4">04</option>
<option value="5">05</option>
<option value="6">06</option>
<option value="7">07</option>
<option value="8">08</option>
<option value="9">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>


i would have to do
Code:


<option value="29" <?php if($day == '29') echo 'selected'; ?>>29</option>
<option value="30"<?php if($day == '30') echo 'selected'; ?>>30</option>
<option value="31"<?php if($day == '31') echo 'selected'; ?>>31</option>


or is there a faster way lol

_Aerospace_Eng_
02-22-2008, 04:45 PM
You really need to check your code and watch what you are typing. You have a pound sign in your code on this line
$dob = &#163;day.'/'.$month.'/'.$year;

That pound sign should be a $.

runnerjp
02-22-2008, 04:51 PM
oh sorry yes i chnaged that abit ago should have metioned that :)

i am trying a loop for my date but its only producing an array of 2's


<?php
for ($optVal=1; $optVal<32; $optVal++) {
$selected = ($day==$optVal)?' selected="selected"':'';
echo "<option value=\"{$optVal}\"{$selected}>" . printf('&#37;02s', $optVal) . "</option>";
}
?>

_Aerospace_Eng_
02-22-2008, 05:11 PM
This is what I use for one of my sites.

<p>
<label for="birthmonth">Birth Month:</label>
<select name="birthmonth" id="birthmonth">
<?php
for($i = 1; $i <= 12; $i++)
{
echo ($i < 10) ? '<option value="0'.$i.'">0'.$i.'</option>' : '<option value="'.$i.'">'.$i.'</option>';
}
?>
</select>
<label for="birthday">Birth Day:</label>
<select name="birthday" id="birthday">
<?php
for($i = 1; $i <= 31; $i++)
{
echo ($i < 10) ? '<option value="0'.$i.'">0'.$i.'</option>' : '<option value="'.$i.'">'.$i.'</option>';
}
?>
</select>
<label for="birthyear">Birth Year:</label>
<select name="birthyear" id="birthyear">
<?php
for($i = 1995; $i >= 1900; $i--)
{
echo '<option value="'.$i.'">'.$i.'</option>';
}
?>
</select>
</p>

runnerjp
02-22-2008, 05:16 PM
ahh thats good but how would i display the currently selected option from the db??

_Aerospace_Eng_
02-22-2008, 05:35 PM
What have you tried? Have you tried anything or were you expecting us to just give you stuff without you trying.

runnerjp
02-22-2008, 06:16 PM
i did
<label for="birthmonth">Birth Month:</label>
<select name="birthmonth" id="birthmonth">
<?php

for($i = 1; $i <= 12; $i++)
{
$selected = ($month==$i)?' selected="selected"':'';
echo ($i < 10) ? '<option value="0'.$i.'"'.$selected.'>0'.$i.'</option>' : '<option value="'.$i.'">'.$i.'</option>';
}
?>

</select>
<label for="birthday">Birth Day:</label>
<select name="birthday" id="birthday">
<?php
for($i = 1; $i <= 31; $i++)
{
echo ($i < 10) ? '<option value="0'.$i.'">0'.$i.'</option>' : '<option value="'.$i.'">'.$i.'</option>';
}
?>
</select>
<label for="birthyear">Birth Year:</label>
<select name="birthyear" id="birthyear">
<?php
for($i = 1995; $i >= 1900; $i--)
{
echo '<option value="'.$i.'">'.$i.'</option>';
}
?>
</select>
</p></td>
</tr> and did not work :(

_Aerospace_Eng_
02-22-2008, 07:15 PM
You aren't pulling them from the database. You are just using the post variables you assigned. You need to run some queries to get the values from the database.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum