-1

I'm working on a PHP based website and have come across an extremely weird issue that I hoping for some type of guidance for.

Whilst creating a sign up page, I've added in all the relevant coding but when adding a test account into the form, I am given this particular error that I seem unable to fix.

"Parse error: syntax error, unexpected end of file in E:\webareas\wo1742o\ucwe_cw\process.php on line 31"

Could anyone possibly provide some clarity as to why this error keeps popping up?

Here's the code used for SQL connection

<?php 
if(!empty($_POST['username']) && !empty($_POST['userpassword'])) {
require 'sqlData.php';

// Database Connection
$link = mysqli_connect($host, $username, $password, $dbname) or die('Failed to connect to MySQL server. ' . mysqli_connect_error($link));

$username = stripslashes($username);
$password = stripcslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);

// get values from form in login.php file
$username = $_POST['username'];
$password = $POST['passname'];

$query = "SELECT id, username, passwod FROM users WHERE username = 
'$username' AND password = '$password'";


// Query the database for user
$result = mysql_query("select * from users where username = '$username' and password = '$password'")  or die('Failed to query database'.mysql_error());

//output data
$row = mysql_query($result);
if ($row['username'] == $username && $row['password'] == $password) {
echo "Login success! Welcome".$row['username'];
} else {
echo "Failed to login";
}
?>
Shadow
  • 33,525
  • 10
  • 51
  • 64
iHugTreez
  • 7
  • 1
  • Never close `if(!empty($_POST['username']) && !empty($_POST['userpassword'])) {` Also you are open to SQL injections and are storing passwords insecurely. `mysqli_connect` doesnt work with `mysql_*`. Also if my password was all slashes you'd be deleting it. – chris85 Dec 19 '16 at 21:15
  • Also dups of http://stackoverflow.com/questions/17498216/can-i-mix-mysql-apis-in-php and http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php – chris85 Dec 19 '16 at 21:16
  • Also all that hackish SQL injection prevention you break with the assignment afterwards. – chris85 Dec 19 '16 at 21:19
  • **DO not use mysql_**: http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php – random_user_name Dec 19 '16 at 22:07
  • Learn to format your code. You wouldn't even be here asking this question if you used proper indenting - it would have been completely obvious. – random_user_name Dec 19 '16 at 22:08
  • you don't have end of 1st `if` block – Adam Silenko Dec 19 '16 at 22:17
  • @cale_b I'd rather not use mySQL for this task but its for a really stupid coursework purpose. Thanks guys for pointing out my idiocy and blindness, I'll be sure to make sure my formatting improves for the final code. Thanks however! I'll be bookmarking the other links as well so I don't run into similar mistakes. Apologies. – iHugTreez Dec 19 '16 at 23:37

1 Answers1

0

You are missing a closing curly bracket for the if statement at the start of the file. Add a } before the ?> at the end of the file.

timk260
  • 129
  • 5
  • That is one of many issues here, i'd also already addressed that in the comments. – chris85 Dec 19 '16 at 21:19
  • Welcome to StackOverflow! And **thank you** for your desire to help. Unfortunately, when you answer a question that is this low quality, you are likely to get downvoted and / or scolded in comments. It would be best to reserve your answers for high-quality questions that show real research effort, are well formatted, and clearly stated. – random_user_name Dec 19 '16 at 22:10