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 li开发者_JS百科ne 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.
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.
Маке
<?php}?>
to
<?php } ?>
And if in first row $pays a php variable. If yes - please echo it
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.
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>
精彩评论