1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need Your Help with PHP Callout in HTML

Discussion in 'White Hat SEO' started by revit, Jun 30, 2009.

  1. revit

    revit BANNED BANNED

    Joined:
    Apr 24, 2009
    Messages:
    266
    Likes Received:
    370
    Sorry, I wasn't quite sure where to post this to request everyones help.

    I am trying to insert a sql callout in an html form.

    This is the script:

    HTML:
    
    
    
    
    <select name="carrier">
    <option value="" selected>-- Carriers --</option>
    <?
    $sql = "SELECT * FROM carriers";
    $result = mysql_query($sql); 
    while($row = mysql_fetch_array($result)) {
    ?>
    <option value="<? echo $row["id"]; ?>">
    <? echo $row["name"]; ?></option>
                                  <?
    }
    ?>
                                </select>
    
    
    
    
    


    It's intended to go inside a dropdown box but I'm having trouble getting it to grab the MySQl information.

    Anyone have any suggestions?
     
  2. thedorf

    thedorf Senior Member

    Joined:
    Oct 1, 2008
    Messages:
    1,193
    Likes Received:
    700
    Occupation:
    what? I gotta have a job?
    Location:
    BHW - Where else?
    Code:
    <option value="<? echo $row["id"]; ?>">
    check the quotes on this line, one of them appears off by your code tags above - the one after id, just delete and replace them all.

    Otherwise, are you getting any errors? Trying just outputing the output without putting it into a dropdown first. ie

    Code:
    while($row = mysql_fetch_array($result)) {
    echo $row["id"].' '; 
    echo $row["name"].'<br>'; 
    }
    
    check your error.log file in your home directory and the directory where the php file is, any errors there?

    Finally, this has to be in a file with an extension of php like something.php (not .htm or .html).
     
    Last edited: Jun 30, 2009
  3. niggles

    niggles Newbie

    Joined:
    May 23, 2009
    Messages:
    38
    Likes Received:
    14
    Occupation:
    Web developer
    Location:
    Melbourne Australia
    Home Page:
    Also check that you're actually connecting to a database! If you haven't done that, you can't call the script - and as the thedorf said, it needs to be on a PHP page (unless you have some tricky mod_rewrite going to make .html parse as .php).

    Cheers,
    Niggles
     
  4. hollinger

    hollinger Junior Member

    Joined:
    Apr 28, 2008
    Messages:
    189
    Likes Received:
    34
    If you are doing mysql querys and would like to debug, try this
    Code:
    mysql_query($sql) or die(mysql_error());
    if there was any error (db not connected etc) it ends scripts work and shows you a error message :)