• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

PHP survey form and dropdown menu (continents)

Hi again!

I am afraid I am asking for a little too much help.

By the way, I am creating an online PHP survey form. I would like to add four  dropdown menu asking respondents to
select (1) the continent of their orgin (example: Europe,  Asia, Africa, Oceania, South America, North America),

(2) Year of Birth (1980 through 1990), (3)  Month of Birth and (4) Date of Birth.

I got help regarding a smiliar matter from wonderful dr_dedo. But I am still trying to figure it out and learn it. As a matter of fact, I am a little running out of time.

The inputs are to be put into a MySql database.

Hope you experts may kindly help me.

Thanks!

duta

June 7, 2006, at 4:07 pm

0
duta
Asked:
duta
  • 3
  • 2
1 Solution
 
dr_dedoCommented:
try this code ( you'll have to create the db)
<?
if (isset($_POST['submit'])){
      $con =  $_POST['con'];
      $date = $_POST['year'].$_POST['month'].$_POST['day'];
      
      mysql_connect('localhost','root','');
      mysql_select_db('db_name');
      
      $sql = " insert into table1 (`con`,`dob`) values ('$con','$date')";
      mysql_query($sql) or die (mysql_error()." in $sql");
      echo "data saved";
      exit();
}
?>
<form method="post" action="<?= $_SERVER['PHP_SELF']?>">
Select continent of origin :
<select name="con">
<option value="Europe">Europe</option>
<option value="Asia">Asia</option>
<option value="Africa">Africa</option>
<option value="Oceania">Oceania</option>
<option value="South America">South America</option>
<option value="North America">North America</option>
</select><br>

Select your birth date :
<select name="year">
<? for ($i=1980;$i<1991;$i++)
echo "<option value='$i'>$i</option>"; ?>
</select>

<select name="month">
<? for ($i=1;$i<13;$i++)
echo "<option value='$i'>".date('M',mktime(0,0,0,$i,1,1999))."</option>"; ?>
</select>

<select name="day">
<? for ($i=1;$i<32;$i++)
echo "<option value='$i'>$i</option>"; ?>
</select>

<input type="submit" name="submit" value="Submit">
</form>
0
 
icb01co2Commented:
dr_dedo's soultion looks spot on, are you still having problems with this?
0
 
dutaAuthor Commented:
TO: dr_dedo and icb01co2:
Yes, dr_dedo's script is working fine. But I have one problem: The probem is that the data input is stored in my MySql database table.

I have been tring to figure it out since last night.

In addition, I have a couple of questions:
The first question is: Is there a way to display the full name of month, instead of 3-letter abridged one?
The second question is: Is there a way to display the dob on the screen and in the database not like current

1121990, but like January 12, 1990?

Here are the scripts that I am using:

__________________ page1.php _____________________________


<HTML>
<HEAD>
<TITLE> Select Page 1 </TITLE>

</HEAD>

<BODY>

<!-- <form method="post" action="<?= $_SERVER['PHP_SELF']?>"> -->


<form method="post" action="input.php">

Select continent of origin :
<select name="con">
<option value="Europe">Europe</option>
<option value="Asia">Asia</option>
<option value="Africa">Africa</option>
<option value="Oceania">Oceania</option>
<option value="South America">South America</option>
<option value="North America">North America</option>
</select><br>

Select your birth date :
<select name="year">
<? for ($i=1980;$i<1991;$i++)
echo "<option value='$i'>$i</option>"; ?>
</select>

<select name="month">
<? for ($i=1;$i<13;$i++)
echo "<option value='$i'>".date('M',mktime(0,0,0,$i,1,1999))."</option>"; ?>
</select>

<select name="day">
<? for ($i=1;$i<32;$i++)
echo "<option value='$i'>$i</option>"; ?>
</select>

<input type="submit" name="submit" value="Submit">
</form>




</BODY>
</HTML>
___________________  input.php  ____________________________




<?
if (isset($_POST['submit']))
{
     $con =  $_POST['con'];
     $date = $_POST['year'].$_POST['month'].$_POST['day'];
     
    $conn= mysql_connect('localhost','my_user_nameuser','my_password');
     mysql_select_db('my_database_name',$conn);
     
     $insert_qry = " insert into select values ('$con','$date')";
     $qry = mysql_query($insert_qry);
     
        if (isset($qry) )
      {
        echo "data saved";
      }
      elseif (!isset($qry) )
     echo "No data input";
}

elseif (!isset($_POST['submit']))
{
      echo "No Submit";
}
?>
________________________________________________

When "Submit" button is clicked, I get a response saying "data saved".
But still when I checked MySQL database, there is no input.

Thanks a lot!

duta

June 8, 2006, at 10:45 am
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
dr_dedoCommented:
to display the full month name, change this
echo "<option value='$i'>".date('M',mktime(0,0,0,$i,1,1999))."</option>"; ?>

to
echo "<option value='$i'>".date('F',mktime(0,0,0,$i,1,1999))."</option>"; ?>


to display date the way you want
echo date('F j Y',mktime(0,0,0,$_POST['month'],$_POST['day'],$_POST['year']));

but DONT save it into db that way or else it will be a tough job to sort using dob
0
 
dutaAuthor Commented:
TO: dr_dedo:

You are just wonderful. Thank you so much for your kind, super-prompt response.

I will do exactly as you kindly advised.

I will come back to you soon!

Thanks again!

duta

June 8, 2006, at 11:28 am
0
 
dutaAuthor Commented:
TO: dr_dedo:

Your script is working just great. But I still experience problems with putting data into MySQL database which is way beyond your control.

I accept your tip with all my heart.

Thanks a lot! Hope you may come back again to help me with other problems.

duta

June 8, 2006, at 11:46 am
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now