tags:

views:

88

answers:

4

Been trying for hours this php embedding in html but something is wrong as i get a error:

Parse error: syntax error, unexpected $end in C:\Program Files\xampp\htdocs\profile.php on line 678

<select value='$pays' name='pays' id='pays' style='width: 204px;margin-bottom: 5px; outline-width:0;'>
<?php
$result = mysql_query("SELECT pays_az, pays_zz, pays_or FROM in_lays WHERE pays_flush = '1' ORDER BY pays_nom ASC");
while ($row = mysql_fetch_array ($result) )
{  ?>
     <option value="<?php echo $row['dd']; ?>"

     <?php   if($row['dd_id'] == $pays)
     {
        echo 'selected="selected" ' ;
     }
     else
     {
           if($row['dd_id'] == "61")
        {
       echo 'selected="selected"' ;
        }
     }
 ?>><?php echo $row['lala']; ?></option>
<?php}?>

</select>

dont pay attention to the names in the sql request.

+2  A: 

The error message “unexpected $end” means that one or more blocks are not properly closed like when a closing } is missing. But your code seems to be correct. You should take a look at your other control structures and see if everything is at its place.


Edit    I think I got it: Though your code seems to be syntactically correct, the <?php}?> is what the parser chokes on. Make it a <?php }?> and it should work.

Gumbo
@Oded: No: `<?php}?>`.
Gumbo
@Oded No, it is not missing...
Himadri
@Gumbo - missed it somehow... disregard me...
Oded
+4  A: 

change <?php}?> to <?php } ?>, i think thats the problem (and you should realy try to format your code better, it's a horror to read that.)

EDIT: without changing too much, i would format your code like this:

<select value="<? echo $pays; ?>" name="pays" id="pays" style="width: 204px;margin-bottom: 5px; outline-width:0;">
    <?
    $result = mysql_query("
            SELECT
                pays_az,
                pays_zz,
                pays_or
            FROM
                in_lays
            WHERE
                pays_flush = '1'
            ORDER BY
                pays_nom ASC
            ");
    while($row = mysql_fetch_array($result)){
    ?>
        <option value="<? echo $row['dd']; ?>"
            <?
            if($row['dd_id'] == $pays || $row['dd_id'] == "61"){
                echo ' selected="selected"';
            }
            ?>
        ><? echo $row['lala']; ?></option>
    <?
    }
    ?>
</select>

Note: i used (evil) short php-tags, but you can change that. i write the opening { in the same linne as the if or while-statement and don't use too much spaces (but that depends on personal preference). the important thing is to indent your code to be readable.

oezi
@oezi Can you explain why <?php}?> doesn't work?
Himadri
@oezi how would you format it?@Himadri , it's just the parser that needs space to recognize the php tag, there it must take all as one entity
tada
@Himadri: as tada mentioned, the compiler needs a space after the opening-tag - @tada: see my edit
oezi
yep, that's a horror. But is there really a way to format PHP inside HTML so that it's not?
Agos
+1  A: 

you did not close the while properly try :

<select value='$pays' name='pays' id='pays' style='width: 204px;margin-bottom: 5px; outline-width:0;'>  
<?php
$result = mysql_query("SELECT pays_az, pays_zz, pays_or FROM in_lays WHERE pays_flush = '1' ORDER BY pays_nom ASC");

while ($row = mysql_fetch_array ($result) ):  ?>

<option value="<?php echo $row['dd']; ?>"

<?php   if($row['dd_id'] == $pays)
{
    echo 'selected="selected" ' ;
}
else
{
    if($row['dd_id'] == "61")
    {
        echo 'selected="selected"' ;
    }
}
?>

<?php echo $row['lala']; ?></option>  

<?php endwhile; ?>

</select>
Nicolo' Verrini
oh.. good... I was not knowing about this alternate syntax..
Himadri
No problem....I think it's always better to use `while(....) endwhile; `
Nicolo' Verrini
+2  A: 

Маке

<?php}?>

to

<?php } ?>

And if in first row $pays a php variable. If yes - please echo it

GOsha
yes! thank you GOsha it was the <?php}?>
tada