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
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;
   }
?>
Link to comment
Share on other sites

<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

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.