2

Parse error: syntax error, unexpected $end in blah/blah/blah.php line 1

This is the error that I receive, with this code

<?php 
include("db.php");

if (isset($_POST['username']) && 
    isset($_POST['password']) && 
    isset($_POST['email']))
{
  //Prevent SQL injections
  $username = mysql_real_escape_string($_POST['username']);
  $email = mysql_real_escape_string($_POST['email']);

  //Get MD5 hash of password
  $password = md5($_POST['password']);

  //Check to see if username exists
  $sql = mysql_query("SELECT username FROM usersystem WHERE username = 'username'");

  if (mysql_num_rows($s > 0))
  {
    die ("Username taken.");
  }

  mysql_query("INSERT INTO usersystem (username, password, email) VALUES ( '$username', '$password', '$email')") 
    or die (mysql_error()); echo "Account created.";
}
?>

I've already checked for unclosed brackets, that's not the problem. Also by troubleshooting with it, I've discovered that the include("db.php"); is causing the problem. When I comment it out, It loads the page just fine. However even when db.php is completely blank, just an empty .php file it still gives me the same error. I'm perplexed. Anyone have any ideas?

here is my db.php file, but honestly when I make db.php completely blank I get the same error. And I am saving it correctly.

<?php
session_start();
mysql_connect("localhost", "mydatabase", "mypassword");
mysql_select_db("ratherda_jetpackfandango");

function user_login ($username, $password)
{
  //take the username and prevent SQL injections
  //$username = mysql_real_escape_string($username);

  //begin the query
  $sql = mysql_query("SELECT * FROM user WHERE username = 'username' AND password = 'password' LIMIT 1");

  //check to see how many rows were returned
  $rows = mysql_num_rows($sql);

  if ($rows<=0 )
  {
    echo "Incorrect username/password";
  }
  else
  {
    //have them logged in
    $_SESSION['username'] = $username;
  }    
}
?>
IAdapter
  • 62,595
  • 73
  • 179
  • 242
Matt
  • 896
  • 5
  • 18
  • 47
  • Slight offtopic - simply running a password through MD5 is not safe anymore this day and age. See this question: http://stackoverflow.com/questions/829838/how-to-store-passwords-correctly – Vilx- May 10 '09 at 07:58
  • 3
    The line "if (mysql_num_rows($s > 0))" should be rewritten to "if (mysql_num_rows($sql) > 0)". Otherwise it will issuse a warning message... – Pafjo May 10 '09 at 08:12

6 Answers6

3

You have a session_start in db.php thats not allowed there. It should be the first line in blah.php.

<?php

session_start();

require_once("db.php");
MrHus
  • 32,888
  • 6
  • 31
  • 31
  • thank you, that solved many of my problems. – Matt May 10 '09 at 22:08
  • Just out of curiosity, why isn't it allowed there? – Sasha Chedygov May 10 '09 at 23:51
  • It's not illegal but having other lines above session start sometimes stops the cookie from being set. Depends on the server configuration as well. But always do it to be save, i've spend hours solving such issues. See the manual comments for more information. – MrHus May 11 '09 at 07:22
2

Post your db.php file, the problem is obviously in there. Unexpected $end errors are usually a result of a missing curly brace, so check that file.

Sasha Chedygov
  • 127,549
  • 26
  • 102
  • 115
2

if (mysql_num_rows($s > 0))

to

if (mysql_num_rows($s) > 0)

Don Wilson
  • 558
  • 2
  • 8
  • 21
0

In php $end errors typically means a missing } brace somewhere.

Joseph Pecoraro
  • 2,858
  • 1
  • 20
  • 25
  • I understand that, But I've already checked for that. I used notepad++ and ever bracket is matched with a closing one. – Matt May 10 '09 at 05:15
0

Perhaps your blah.php file is included from another blahblah.php file, and the error is there?

Vilx-
  • 104,512
  • 87
  • 279
  • 422
0

Are you sure that it's your db.php that get included? Could it be another db.php somewhere in your php-paths that get included instead? One way to check this is to rename your file to something more unique.

Pafjo
  • 4,979
  • 3
  • 23
  • 31