Jump to content

help with php select menu


stelthius

Recommended Posts

Hello everyone,

 

Im in need of a little assistance with my menu for date of birth,

 

basicly all 3 results need to be entered into one table in the database 'dob' but im unsure how to do that from the point im at right now,

 

 

<?php

echo '<select name="day" size="1">';
for ($x = 1; $x <= 31; $x++)
{
if ($form->value("day") == $x)
	$added = ' selected="selected"';
else
	$added = '';
echo "<option value='$x'$added>$x</option>";
}
echo '</select>';

$months = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');

echo '<select name="month" size="1">';
for ($x = 0; $x < sizeof($months); $x++)
{
if ($form->value("month") == $months[$x])
	$added = ' selected="selected"';
else
	$added = '';
echo "<option value='$months[$x]'$added>$months[$x]</option>";
}
echo '</select>';

$year = date("Y");
$firstYear = $year - 13;
$finalYear = $year - 100;
echo '<select name="year" size="1">';
for ($x = $firstYear; $x >= $finalYear; $x--)
{
if ($form->value("year") == $x)
	$added = ' selected="selected"';
else
	$added = '';
echo "<option value='$x'$added>$x</option>";
}
echo '</select>';
?>

 

My general problem is getting it to input all 3 selected options in to 1 table in the database called dob as said above. any help is greatly appretiated.

 

 

Link to comment
Share on other sites

Can't you just put the 3 form field together and do a insert into the DB? Do you know how to make the connection to you database and run query's?

 

<?php
     
        $month = mysql_real_escape_string($_POST['month']);
$day = mysql_real_escape_string($_POST['day']);
$year = mysql_real_escape_string($_POST['deadline_year']);

$birthDate = $year."-".$month."-".$day;
       

?>


Just include that into your query and run it, hope this helps.

Link to comment
Share on other sites

Thanks for your reply stephen but your miss understanding the question im not asking anything about connecting to the DB im asking is there anyways using php to get 3 drop down menu's to post into one table in the database,

 

so in my situatiion i have menu 1 |day| menu 2 |month| menu 3 |year| now i want to put all 3 of the selected results into one table called dob, so im asking is there anyway to get day,month,year to go into dob or would i have to use a seperate table for each one,

Link to comment
Share on other sites

The code I showed you puts it into one var and you just insert it into the MySql table.

 

<?php
   //Put your DB Connection code and select DB code hree.
   $link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
   $db_selected = mysql_select_db('dob', $link);
    
   //Now get the date and make it so that it will go into a MySql date field
   $month = mysql_real_escape_string($_POST['month']);
   $day = mysql_real_escape_string($_POST['day']);
   $year = mysql_real_escape_string($_POST['deadline_year']);

   $birthDate = $year."-".$month."-".$day;
       
  //Insert the date into the database
  $query = "INSERT INTO dob (dateField) VALUE ($dirthDate)";
  $result = mysql_query($query);

?>


 

 

Or something along those lines, I wrote that off the top of me head and code might not be 100% right. It should be good enough to show you what I was talking about though.

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.