douxianxing5712 2013-09-13 23:49
浏览 49
已采纳

PHP意外的T_Variable实际上并不存在

So, I was trying to write a PHP authentication system, but I cannot run it without getting an error. Specifically, it says the following:

Parse error: syntax error, unexpected '$name' (T_VARIABLE) in C:\Apache24\htdocs\struct\generalesourcesoot~index\User.php on line 6

I then looked it up, and found out that the error was a common one. However, what was different about mine was that the '$name' variable didn't actually exist. In fact, line 6 is the closing bracket of a function. Here is the full code:

<?php

include 'User.php';
function sha512($data){
return hash('sha512', $data);
}//This is line 6
?> 
<html><head><title>Login</title></head><body background="/struct/general/resources/root~index/images/Pig.jpg"<p>Your request is being processed.     Please Wait...</p><br />
<?php
$username = htmlspecialchars($_POST['__INPUT_2']);
$passwordhash = sha512(htmlspecialchars($_POST['__INPUT_1']));

$user_file_path = $_SERVER['DOCUMENT_ROOT'] . '/struct/data/user/data';

$isUser = file_exists($user_file_path . $username . '$' . $passwordhash);



$user = new User($username, $passwordhash);

?>

By the way, I am somewhat of a beginner to PHP, so I'm not sure if I matched all the conventions correctly. Anyways, my question is this: Why am I getting an error about a mysterious variable called '$name' when that variable does not exist within the scope of my code, and how should I fix this?

  • 写回答

1条回答 默认 最新

  • drbd65446 2013-09-14 00:10
    关注

    PHP error reporting is precise in what it states. PHP doesn't lie, even if the actual issue in your code is not the error and/or line PHP has stated in the error.

    ie unexpected end at line 200. It might be a missing curly brace at line 140. You need to read about the errors, search for them here and in Google.

    "unexpected" anything in PHP errors is usually straight cut, in that it was expecting something before whatever is mentioned in the error.
    In this case, unexpected '$name' (T_VARIABLE), your $name variable was not expected, PHP was expecting a closing bracket, or comma, or semi colon to end the previous line, something else.

    Look at your line 6 in your file User.php. If that line is absolutely fine, then the error is before it, again, perhaps a missing semi colon for the previous line.

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

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图