Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP Output Problem

    I'm trying to get a simple php script to populate a dropdown box.. the php code works as a standalone .php, but when I add it to the HTML file with some other forms and view the page, it fails.. So the code is solid, I think it must be a problem with the echo statements?! I don't even get the dropdown box! Any suggestions?

    Code:
    <form action="handle.php" action="POST">
      <input type="text" name="amount">amount
      <input type="text" name="category">category
      <input type="text" name="description">description
    
    <?
    $dbh=mysql_connect ("localhost", "branthan_et", "password") or die ('I cannot connect to the database because: ' . mysql_error());
    
    mysql_select_db ("branthan_expensetracker");
    
    $sqlOptions = "SELECT * from categories";
    
    $resultOptions = mysql_query($sqlOptions);
    
    
    echo '<select name="selectName">';
    
    echo '<option value="">--Select--</option>';
    
    while($opt = mysql_fetch_array($resultOptions))
    {
    echo '<option value="'.$opt['categories'].'">'.$opt['categories'].'</option>';
    }
    
    echo '</select>'; 
    ?>
    
    
      <input type="text" name="payment">payment
      <input type="text" name="amount">amount
      <input type="text" name="date">date
    </form>

  • #2
    Regular Coder
    Join Date
    Sep 2005
    Posts
    394
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Do you get any errors?

    ~Phil~

  • #3
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nope, no errors.. I'll post the output..

    Code:
    amount category description '; echo '--Select--'; while($opt = mysql_fetch_array($resultOptions)) { echo ''.$opt['categories'].''; } echo ''; ?>  payment amount date
    The drop-down box should be after description, so the output of what should be the dropdown box is

    '; echo '--Select--'; while($opt = mysql_fetch_array($resultOptions)) { echo ''.$opt['categories'].''; } echo ''; ?>

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    What is the source code of the page after it's built (from the browser)?

  • #5
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fumigator
    What is the source code of the page after it's built (from the browser)?
    Well here's the updated code.. no echo errors, but now nothing is listed in the dropdown box.

    <form action="handle.php" action="POST">
    <input type="text" name="amount">amount
    <input type="text" name="category">category
    <input type="text" name="description">description

    <select name="selectName">


    <?php


    $dbh=mysql_connect ("localhost", "branthan_et", "password") or die ('I cannot connect to the database because: ' . mysql_error());
    mysql_select_db ("branthan_expensetracker");

    $sqlOptions = "SELECT * FROM categories";
    $resultOptions = mysql_query($sqlOptions);

    while($opt = mysql_fetch_assoc($resultOptions))
    {
    echo "<option value=\"".$opt['categories']."\"></option>";
    }

    ?>
    </select>
    </form>


    Actually the source for the page is the same as what I posted.. I didn't think it should be showing the php code?


  •  

    Posting Permissions

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