dongshanxiao7328 2013-08-15 19: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 19: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...

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

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教