doushenjia8514
doushenjia8514
2012-11-13 22:53

输入html标签在php中没有正确解析[重复]

已采纳

Possible Duplicate:
Parse error: syntax error, unexpected T_STRING 59

I have a database with names that I would like displayed in the form of a table with checkboxes. Everything works until I try to place the html tag into my php code. When I put the input tag in it gives me the error:

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'

I can't see where I would put a comma or semi colon.

<form>
    <?php
    $name = $_POST['name'];

    $host = "mysql16.000webhost.com";
    $user_name = "a1611480_akaash";
    $pwd = "****";
    $database_name = "a1611480_akaash";
    $db = mysql_connect($host, $user_name, $pwd);

    mysql_select_db($database_name);

    $result = mysql_query("SELECT name FROM Sort");

    $var = array();
    while ($row = mysql_fetch_array($result)) {
        $var[] = $row['name'];
    }

    $unique = array_unique($var);

    foreach ($unique as $value) {

        echo "<p class = Body_text><label>$value</label> <input type="checkbox" name="name" value="$value" /> </p>
";
    }
    ?>
</form>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

5条回答

  • douboshan1466 douboshan1466 9年前

    Replace this:

    echo "<p class = Body_text><label>$value</label> <input type="checkbox" name="name" value="$value" /> </p>
    "
    

    with this:

    echo <<<EOD
    <p class = Body_text><label>$value</label> <input type="checkbox" name="name" value="$value" /> </p>
    EOD;
    

    ... This uses HEREDOC syntax, which easily bypasses most of your quotation issues. However, it comes with an important caveat: the line EOD; must not be indented and there cannot be anything else on that line (such as trailing spaces).

    点赞 评论 复制链接分享
  • dongmeiwei0226 dongmeiwei0226 9年前

    You need to escape your backslashes, or perhaps use heredoc syntax. See below for a couple of examples where you're breaking your PHP code:

    echo "<p class = Body_text><label>$value</label> <input type="checkbox" name="name" value="$value" /> </p>
    ";
                                                                ^^^      ^^^
    
    点赞 评论 复制链接分享
  • duandao3265 duandao3265 9年前

    change this line.. u have to escape doublequotes

    echo "<p class = Body_text><label>$value</label> <input type=\"checkbox\" name=\"name\" value=\"$value\" /> </p>
    ";
    
    点赞 评论 复制链接分享
  • dongwenyou4298 dongwenyou4298 9年前

    Replace the "echo" line with

    echo "<p class = Body_text><label>$value</label> <input type='checkbox' name='name' value='$value' /> </p>
    ";
    

    Because you use double quotes as a string delimiter and also for the checkbox itself, it kinda breaks out of the php string.

    点赞 评论 复制链接分享
  • doushuhuai7247 doushuhuai7247 9年前

    On your echo line, the entire thing must be surrounded by double quotes. You open the double quotes before checkbox so it is seeing checkbox as an unknown PHP call. Use a combination of single and double quotes.

    点赞 评论 复制链接分享