解析错误:语法错误,意外的T_VARIABLE php

时间:2012-10-28 03:30:51

标签: php

  

解析错误:语法错误,第4行/home/content/00/7882800/html/Connections/dueslogin.php中的意外T_VARIABLE

尝试连接到godaddy数据库,由于php错误而无法连接。

<?php
        //Variables for connecting to your database.
        //These variable values come from your hosting account.
        $hostname = "Squarepants.db.7882800.hostedresource.com";
        $username = "Squarepants";
        $dbname = "Squarepants";

        //These variable values need to be changed by you before deploying
        $password = "***********";
        $usertable = "Spongebob";
        $username = "username";
        $password = "password";

        //Connecting to your database
        mysql_connect($hostname, $username, $password) OR DIE ("Unable to 
        connect to database! Please try again later.");
        mysql_select_db($Squarepants);

        //Fetching from your database table.
        $query = "SELECT * FROM $usertable";
        $result = mysql_query($query);

        if ($result) {
            while($row = mysql_fetch_array($result)) {
                $name = $row["$yourfield"];
                echo "Name: $name<br>";
            }
        }
?>

2 个答案:

答案 0 :(得分:1)

我能够在我的计算机上编译这个脚本而没有任何语法错误。

$ php yourcodecopiedandpasted.php 
$ php -l yourcodecopiedandpasted.php 
No syntax errors detected in foo.php
$ php --version
PHP 5.3.15 with Suhosin-Patch (cli) (built: Jul 31 2012 14:49:18) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

答案 1 :(得分:1)

第4行应来自包含的文件Connections/dueslogin.php

您可能需要发布该内容,以便我们检查错误。当前文件很好,似乎没有任何错误。