PHP - 发布语法错误

时间:2017-09-28 07:51:09

标签: php html forms contact-form

这是我从。

获取语法错误的代码
<?php 
    if ($_POST['prestiti']){
        echo "<option value=".$_POST['prestiti']." 
        selected='selected'>.$_POST['prestiti']</option>";}    
    else{
        echo "<option value='No' selected='selected'>No</option>";}
?>

错误 - &gt ;;

unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or 
T_NUM_STRING in line

提前谢谢!

2 个答案:

答案 0 :(得分:1)

您有连接错误。您的错误符合要求:selected='selected'>.$_POST['prestiti']您忘记了"

我已在下面的代码中解决了这些错误

<?php 
     if ($_POST['prestiti']){
        echo "<option value=".$_POST['prestiti']." selected='selected'>".$_POST['prestiti']."</option>";}
     else{
        echo "<option value='No' selected='selected'>No</option>";
    }
?>

答案 1 :(得分:0)

试试这个;

if (isset($_POST['prestiti']) && $_POST['prestiti'] != ""){
   echo "<option value=".$_POST['prestiti']." selected='selected'>" . $_POST['prestiti'] ."</option>";
}else{
   echo "<option value='No' selected='selected'>No</option>";
}