Jump to content

php page to populate database


omega1983

Recommended Posts

I have an html form that allows user to enter data.  Data type for the most part is text.  I want to have a drop down to allow people to choose and have it populate a database.

 

In the database I have

golfer_1

golfer_2

golfer_3

 

How can I create the drop down so that php will populate base on the choice made by customer and have it populate the database. I am ok with the populating based on text

 

Link to comment
https://forums.phpfreaks.com/topic/285216-php-page-to-populate-database/
Share on other sites

Something like this:

<form id="frmGolfer" name="frmGolfer" action="" method="post">
  <select id="seGolfer" name="seGolfer" size="1">
     <option value="golfer_1">Golfer 1</option>
     <option value="golfer_2">Golfer 2</option>
     <option value="golfer_3">Golfer 3</option>
  </select>
</form>

$(document).ready(function(){
    $("#seGolfer").change(function(){
        document.getElementById("frmGolfer").submit();
    });
});

In your PHP page, switch...case syntax should be used to process the case of which golfer being selected, as follows:

<?php
   $golfer = $_POST["seGolfer"];
   switch ($golfer)
   {
       case 'golfer_1':
           // Code to process the case of golfer_1 being selected
       break;

       case 'golfer_2':
           // Code to process the case of golfer_2 being selected
       break;

       case 'golfer_3':
           // Code to process the case of golfer_3 being selected
       break;
   }
?>
<script type="text/javascript" language="javascript">
//<![CDATA[

    $(document).ready(function(){
        $("#seGolfer").change(function(){
           document.getElementById("frmGolfer").submit();
        });
    });

//]]>	
</script>

I am sorry for forgetting putting JavaScript code in script tags

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.