A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [RESOLVED] PHP Parse Error on Line 1?

  1. #1
    Senior Member
    Join Date
    Jun 2002
    Posts
    400

    resolved [RESOLVED] PHP Parse Error on Line 1?

    Friends,

    I'm getting a weird error. My code basically writes high scores to a MySQL database. It has worked for months. I created a new database just fine. But when I made an exact copy of my PHP and simply changed the name of the target database, it started throwing this error...

    Parse error: syntax error, unexpected T_VARIABLE in /.../deposit.php on line 1"

    There's nothing on line 1 except <?php and I've checked for missing semicolons and whatnot.

    Any help would be greatly appreciated!

    Actionscript Code:
    <?php

    $dbhost = 'localhost';
    $dbuser = '***';
    $dbpass = '***';
    $dbname = '***';
    $dbtable = '***';

    $con = mysql_connect($dbhost,$dbuser,$dbpass);
    if(!$con) {
        die('Failed to connect to server: ' . mysql_error());
    }

    $db = mysql_select_db($dbname);
    if(!$db) {
        die("Unable to select database");
    }

    //Function to sanitize values received from the form. Prevents SQL injection
    function clean($str) {
        $str = @trim($str);
        if(get_magic_quotes_gpc()) {
            $str = stripslashes($str);
        }
        return mysql_real_escape_string($str);
    }
       
    //Sanitize the POST values
    $name = clean($_POST['name']);
    $score = clean($_POST['score']);
    $rightanswers = clean($_POST['rightanswers']);
    $wronganswers = clean($_POST['wronganswers']);
    $date = date("Y/m/d");
           

    //Create INSERT query
    $qry = "INSERT INTO $dbtable(name,score,rightanswers,wronganswers,date) VALUES('$name','$score','$rightanswers', '$wronganswers', '$date')";
    $result = @mysql_query($qry);

    echo "writing=Ok";
    exit();

    mysql_close();

    ?>

  2. #2
    Senior Member
    Join Date
    Jun 2002
    Posts
    400
    A buddy discovered that if I added mysql_close(); after the echo call and before the exit call, he could get it to work. That fixed it up.

  3. #3
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    to be honest, I would not believe that adding code after an exit(); call could fix a problem. I would rather expect that there was a problem with unexpected characters which got solved by using a different editor (or different editor settings)
    I recall a non-working script copy/pasted from a web page ... to preserve the spacing there were alternating regular and non-breaking spaces in the text, and php did not really appreciate the latter ones

    Musicman

  4. #4
    Senior Member
    Join Date
    Jun 2002
    Posts
    400
    MusicMan,

    You are absolutely right. Turns out there were some bad returns in there that I couldn't see. I think my Dreamweaver settings were jacked and added ^Ms after every line.

    Thanks for clarifying.

    -Layne

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center