解析错误:语法错误,第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?
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...