Please help me with this syntax error

Discussion in 'PHP' started by afridy, Sep 18, 2014.

  1. #1
    Hai folks,

    the 12 and 13 lines are having a syntax issue. but i could not figure it out. pls help me.

    <?php
    echo "<select name=" . $select_name . " id=" . $select_id . ">";
       echo "<option value="Select">Select</option>";
     
        require_once('../includes/connection.php');
                     
        $query="SELECT * FROM " . $table . "
                ORDER BY " . $order_column . " ASC";
    
        if ($result=mysql_query($query) or die (mysql_error()));
        while($row=mysql_fetch_array($result)){
           $value=$row['" . $value_column . "']; //xxxx
           $name=$row['" . $name_column . "'];//xxxx
           echo "<option value='" . $value . "'>" . $name . "</option>";
        }
    
        echo "</select>":
    
    ?>
    
    PHP:
     
    afridy, Sep 18, 2014 IP
  2. homer7

    homer7 Well-Known Member

    Messages:
    268
    Likes Received:
    25
    Best Answers:
    4
    Trophy Points:
    125
    #2
    Hi

    on line 3 you have to escape the double quotes inside double quotes with back slash or alternate with single quotes

    echo "<option value=\"Select\">Select</option>";
    or
    echo "<option value='Select'>Select</option>";

    and replace the colon with semicolon on the last line.
     
    homer7, Sep 18, 2014 IP
  3. afridy

    afridy Well-Known Member

    Messages:
    810
    Likes Received:
    116
    Best Answers:
    0
    Trophy Points:
    135
    #3
    Thanks homer7 ,
    i fixed it. but what about line 12 and 13 (in my first post)

    <?php
    echo "<select name='" . $select_name . "' id='" . $select_id . "'>";
       echo "<option value='Select'>Select</option>";
       
        require_once('../includes/connection.php');
                       
        $query="SELECT * FROM " . $table . "
                ORDER BY " . $order_column . " ASC";
    
        if ($result=mysql_query($query) or die (mysql_error()));
        while($row=mysql_fetch_array($result)){
           $value=$row['" . $value_column . "'];
           $name=$row['" . $name_column . "'];
           echo "<option value='" . $value . "'>" . $name . "</option>";
        }
    
        echo "</select>":
    
    ?>
    PHP:
     
    afridy, Sep 18, 2014 IP
  4. homer7

    homer7 Well-Known Member

    Messages:
    268
    Likes Received:
    25
    Best Answers:
    4
    Trophy Points:
    125
    #4
    you don't need quotes there
    $value=$row[$value_column];
    $name=$row[$name_column];
     
    homer7, Sep 18, 2014 IP
  5. afridy

    afridy Well-Known Member

    Messages:
    810
    Likes Received:
    116
    Best Answers:
    0
    Trophy Points:
    135
    #5
    oh , cool :D
     
    afridy, Sep 18, 2014 IP
  6. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #6
    Would also be wise to just suggest using single quotes for the echo statements, so you don't have to escape anything, like so:
    
    echo '<p class="something">This is a text</p>';
    //or
    echo '<p class="something">'.$this_is_a_variable.'</p>';
    
    PHP:
     
    PoPSiCLe, Sep 18, 2014 IP
  7. afridy

    afridy Well-Known Member

    Messages:
    810
    Likes Received:
    116
    Best Answers:
    0
    Trophy Points:
    135
    #7
    GOT IT FOLKS,
     
    afridy, Sep 18, 2014 IP