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
https://forums.phpfreaks.com/topic/148158-help-with-php-select-menu/
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.

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,

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.