Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 3 of 3

Thread: Database Generated Drop Down List

  1. #1

    Database Generated Drop Down List

    Hi there,

    New to the forums, and I use Kirupa allot, so thought I would come allong and join the discussions.

    Basically, I am trying to make a drop down HTML form object read values of a certain database table and make them selectable. Here is what I currently have:

    PHP Code:
    <?php
        
    require 'dbinc.php';
        
        
    $result mysql_query("SELECT * FROM servers")
            or die(
    mysql_error());    
        
        <
    form action="adddomain.php" method="POST" enctype="text/plain">
            <
    select size="20" height="1">
                while(
    $row mysql_fetch_array$result )) {
                    echo <
    option value="echo $row ['name'];"</option>
                }
            </
    select>
            <
    input type="text" value="" name="servername" tabindex="2" />
            <
    input type="text" value="" name="serverip" tabindex="3" />
            <
    input type="text" value="" name="admuser" tabindex="4" />
            <
    input type="text" value="" name="admpass" tabindex="5" />
            <
    input type="submit" value=""/>
        </
    form>
        
        
    $serverid $_POST["serverid"];
        
    $servername $_POST["servername"];
        
    $domainid $_POST["domainid"];
        
    $domainname $_POST["domainname"];
        
    $nsbool $_POST["nsbool"];
        
    $nserver1 $_POST["nserver1"];
        
    $nserver2 $_POST["nserver2"];
        
    $wwwrecord $_POST["wwwrecord"];
        
    $mailrecord $_POST["mailrecord"];
        
    $ftprecord $_POST["ftprecord"];
        
        
    /**
    * variable nsbool defines whether the records on a particular domain are directed using name servers or just specific records - 1 equals specific records whereas 0 equals nameservers in use only
    */
        
        
    mysql_query("INSERT INTO domains (serverid, servername, domainid, domainname, nsbool, nserver1, nserver2, wwwrecord,                mailrecord, ftprecord)
            VALUES('
    $serverid', '$servername', '$domainid', '$domainname', '$nsbool', '$nserver1', '$nserver2', '$wwwrecord'                ,'$mailrecord', '$ftprecord') "
            or die(
    mysql_error());
    ?>
    I understand things are a little messed up here, but you should get the idea of what I am doing. Has anyone done this and what method did they use to achieve the desired results?

    Thanks!
    Last edited by jheath; February 7th, 2007 at 05:54 AM.

  2. #2
    602
    posts
    Backend Specialist
    PHP Code:
    <?php
        
    require 'dbinc.php';
        
        
    $result mysql_query("SELECT * FROM servers")
            or die(
    mysql_error());    
        
    ?>
        <form action="adddomain.php" method="POST" enctype="text/plain">
            <select size="20" height="1">
            <?
              
    while($row mysql_fetch_array$result )) {
                    echo 
    "<option value=\"" $row ['name'] . "\">" $row ['name'] . "</option>";
               }
          
    ?>
         </select>
            <input type="text" value="" name="servername" tabindex="2" />
            <input type="text" value="" name="serverip" tabindex="3" />
            <input type="text" value="" name="admuser" tabindex="4" />
            <input type="text" value="" name="admpass" tabindex="5" />
            <input type="submit" value=""/>
        </form>
        <?
        $serverid 
    $_POST["serverid"];
        
    $servername $_POST["servername"];
        
    $domainid $_POST["domainid"];
        
    $domainname $_POST["domainname"];
        
    $nsbool $_POST["nsbool"];
        
    $nserver1 $_POST["nserver1"];
        
    $nserver2 $_POST["nserver2"];
        
    $wwwrecord $_POST["wwwrecord"];
        
    $mailrecord $_POST["mailrecord"];
        
    $ftprecord $_POST["ftprecord"];
        
        
    /**
    * variable nsbool defines whether the records on a particular domain are directed using name servers or just specific records - 1 equals specific records whereas 0 equals nameservers in use only
    */
        
        
    mysql_query("INSERT INTO domains (serverid, servername, domainid, domainname, nsbool, nserver1, nserver2, wwwrecord,                mailrecord, ftprecord)
            VALUES('
    $serverid', '$servername', '$domainid', '$domainname', '$nsbool', '$nserver1', '$nserver2', '$wwwrecord'                ,'$mailrecord', '$ftprecord') "
            or die(
    mysql_error());
    ?>
    Maybe something like this. You aren't using the <? ?> to separate your PHP from HTML.

  3. #3
    Thanks for that sk00b, I'm aware I wasn't opening and closing properly, just focused on the drop down at the moment, but you seem to have nailed it.

    Quote Originally Posted by skOOb View Post
    PHP Code:
    <?php
        
    require 'dbinc.php';
        
        
    $result mysql_query("SELECT * FROM servers")
            or die(
    mysql_error());    
        
    ?>
        <form action="adddomain.php" method="POST" enctype="text/plain">
            <select size="20" height="1">
            <?
              
    while($row mysql_fetch_array$result )) {
                    echo 
    "<option value=\"" $row ['name'] . "\">" $row ['name'] . "</option>";
               }
          
    ?>
         </select>
            <input type="text" value="" name="servername" tabindex="2" />
            <input type="text" value="" name="serverip" tabindex="3" />
            <input type="text" value="" name="admuser" tabindex="4" />
            <input type="text" value="" name="admpass" tabindex="5" />
            <input type="submit" value=""/>
        </form>
        <?
        $serverid 
    $_POST["serverid"];
        
    $servername $_POST["servername"];
        
    $domainid $_POST["domainid"];
        
    $domainname $_POST["domainname"];
        
    $nsbool $_POST["nsbool"];
        
    $nserver1 $_POST["nserver1"];
        
    $nserver2 $_POST["nserver2"];
        
    $wwwrecord $_POST["wwwrecord"];
        
    $mailrecord $_POST["mailrecord"];
        
    $ftprecord $_POST["ftprecord"];
        
        
    /**
    * variable nsbool defines whether the records on a particular domain are directed using name servers or just specific records - 1 equals specific records whereas 0 equals nameservers in use only
    */
        
        
    mysql_query("INSERT INTO domains (serverid, servername, domainid, domainname, nsbool, nserver1, nserver2, wwwrecord,                mailrecord, ftprecord)
            VALUES('
    $serverid', '$servername', '$domainid', '$domainname', '$nsbool', '$nserver1', '$nserver2', '$wwwrecord'                ,'$mailrecord', '$ftprecord') "
            or die(
    mysql_error());
    ?>
    Maybe something like this. You aren't using the <? ?> to separate your PHP from HTML.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012