0

Im getting an error on line 4, The curly bracket. From what i know the bracket needs to be there. How can i fix this ?

<?php
include('config.php');
// for the registration script we need a html form
if($_SERVER['REQUEST_METHOD'] == 'POST' {
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string(md5($_POST['password']));
//retrieve the input from the user and encrypt the password with md5
 } if(empty($username)) {
echo("Please enter a Username");
} else {
if(empty($password)) {
echo("Please enter a password");
} else {
//check if username already exists
$query = mysql_query("SELECT * FROM users WHERE username='$username'");
$rows = mysql_num_rows($query);
//with mysql_query you call a sql command 
if($rows > 0) {
    die("Username taken !!");
    } else {
    $user_input = mysql_query("INSERT INTO users (username , password) VALUES     ('$username' , '$password')");
    echo("Successfully Registered ");
    }
}
}
?>
  • In which environment do you program? Maybe Netbeans is a idea? It will help you with debugging. – Pakspul Jan 17 '14 at 23:01
  • I use notepad++ Ive tried other programmes like aptana studio and netbeans, but i honestly prefer notepad++ just because of its simplicity – user3208543 Jan 17 '14 at 23:07

1 Answers1

3

Change

if($_SERVER['REQUEST_METHOD'] == 'POST' {

To

if($_SERVER['REQUEST_METHOD'] == 'POST') {

You're missing a closing )

Also Don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO, or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

And do not store user passwords using MD5, this is nearly as bad as plain-text

Zoe
  • 27,060
  • 21
  • 118
  • 148
Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106