dongshanxiao7328 2013-08-15 11:34
浏览 55
已采纳

解析错误:语法错误,第1行myfile中的意外$ end [关闭]

Here's my code:

<?php

if(empty($_POST['id']))
{
    echo '<form method="post"><input type="text" name="id"><input type="submit" value="go"></form>';
}
else
{   

    $con=mysqli_connect("localhost","adminuser","adminpassword","database");
    // Check connection
    if (mysqli_connect_errno())
    {
        die("dbconnect failed: " . mysqli_connect_error());
    }

    $remoteEndpoint=$_SERVER["REMOTE_ADDR"].".".$_SERVER["REMOTE_PORT"];
    $hash = md5(uniqid());
    $code= mysql_real_escape_string($_POST['id']);

    mysqli_query($con,"INSERT INTO `mobile` (`useragent`, `ip`, `hash`) VALUES ('".$code."', '".$remoteEndpoint."','".$hash."')");

    echo hash;
}

?>

With this, I'm getting

 Parse error: syntax error, unexpected $end in /mylocation/index.php on line 1

I've checked all the branches and I can't find anything.

Did I miss something?

展开全部

  • 写回答

1条回答 默认 最新

  • dsiuy42084 2013-08-15 11:52
    关注

    You code does not report the error you suggest "error: syntax error, unexpected $end"

    I've tested it on my local dev and while I obviously get access denied warning for the mysql connection, there are no PHP errors.

    There is a notice: "PHP Notice: Use of undefined constant hash - assumed 'hash' "

    Because as pointed out by Marc B you missed the $ on the end of your "hash" var.

    This means there must be more to your code, and the actual issue is in there somewhere. Commonly (note, not always, but often) the unexpected $end error is due to a missing curly bracket (ie you opened an IF but didn't close it). Check those first. If you don't use an editor with syntax highlighting, you should as it often saves time on those daft typos and late-night-tired mistakes...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部