0

HI i've got an error on line 20 i have tried mysqli

Parse error: syntax error, unexpected 'mysql_query' (T_STRING) in C:\Users\User\l\htdocs\register.php on line 20

    <html>
<body>
<?php
include("connect.php");

if(isset($_POST['register']))
$username= strip_tags(trim(mysql_real_ecape_string($_POST['username'])));
$password= strip_tags(trim(mysql_real_ecape_string($_POST['password'])));

    if(!username || !$password){
    echo "One of the fields are empty";
    }else{
    $find_multiple=" SELECT Username FROM register WHERE Username='$username' ";
    $run_multiple = mysql_query($find_multiple) or die (mysql_error());
    $num_multiple= mysql_num_rows($run_multiple);

    if($num_multiple < 1){
    $password= md5($password)

    mysql_query("INSERT INTO register SET Username='$Username', Password='$Pasword' ") or die(mysql_error());
    echo "You have succesfully registered!":

    }else{
    echo "That username has already beed used" ;

    }

?>  


<h1>Register</h1>
<form action='' method='post'>
username: <input type='text' name'username'/></br>
Password: <input type='password' name'password'/></br>
<input type='submit' value='Register'name='register'/>
</form> 

Notice: Undefined index: username in C:\Users\User\l\htdocs\register.php on line 12

Notice: Undefined index: password in C:\Users\User\l\htdocs\register.php on line 13

<?php
    $connect=mysql_connect("localhost","root","");
    $db_selected = mysql_select_db("users", $connect); 


    if(isset($_POST['register'])){


    $username= $_POST['username'];
    $password= $_POST['password'];

        if(!$username || !$password){
        echo "One of the fields are empty";
        }else{
        $find_multiple=" SELECT username FROM resgistration WHERE username='$username' ";
        $run_multiple = mysql_query($find_multiple) or die (mysql_error());
        $num_multiple= mysql_num_rows($run_multiple);

        if($num_multiple < 1){
        $password= md5($password);

        mysql_query( "INSERT INTO `resgistration` (`username`, `password`) VALUES ('".$username."', '".$password."')" ) or die(mysql_error());
        echo "You have succesfully registered!";

        }else{
            echo "That username has already beed used" ;
    } 

         } # endelse: empty password or username
    } # endif: registered
    ?>  
    <head>
    <h1>Register</h1>
    <form action='' method='post'>
    Username: <input type='text' name='username'/></br>
    password: <input type='password' name='password'/></br>
    <input type='submit' value='Register'name='register'/>

    </form> 
    </body>
    </html>
dean012
  • 13
  • 2
  • 5

6 Answers6

0

Missing ; in this line:

$password= md5($password)
Ramesh
  • 4,223
  • 2
  • 16
  • 24
0

Put a semi-colon on the preceding line. PHP uses ; as statement terminators, and they're not optional.

alex
  • 479,566
  • 201
  • 878
  • 984
0

You need a semicolon after this line:

$password= md5($password)

You also have a colon (should be a semicolon) after:

 echo "You have succesfully registered!":

You should read about how to debug PHP errors by yourself, so that you can start fixing simple bugs like this.

Community
  • 1
  • 1
Bailey Parker
  • 15,599
  • 5
  • 53
  • 91
0

you missed semicolon in line 19.

also INSERT INTO [TABLE] SET is not standard somehow. try this format:

  mysql_query("INSERT INTO `register` (`username`, `password`) VALUES 
               ('$username', '$password')");
Mohammad Ali
  • 96
  • 1
  • 7
  • Parse error: syntax error, unexpected end of file in C:\Users\User\l\htdocs\register.php on line 38 – dean012 Nov 28 '13 at 08:21
  • seems you missed `code`}`code` also the whole line would be: `code`mysql_query("INSERT INTO 'register' ('username', 'password') VALUES ('$username', '$password')"); or die(mysql_error()); `code` – Mohammad Ali Nov 28 '13 at 08:27
  • i tried mysql_query("INSERT INTO 'register' ('username', 'password') VALUES ('$username', '$password')"); die(mysql_error()); – dean012 Nov 28 '13 at 08:30
  • Parse error: syntax error, unexpected end of file in C:\Users\User\l\htdocs\register.php on line 42 – dean012 Nov 28 '13 at 08:30
0

Try this:

<?php
    $connect=mysql_connect("localhost","root","");
    $db_selected = mysql_select_db("users", $connect); 

    if( isset( $_POST['hide'] ) && $_POST['hide'] == 1 ) {

        $username= $_POST['username'];
        $password= $_POST['password'];

        if( !$username || !$password ) {
            echo "One of the fields are empty";
        } else {
            $find_multiple = "SELECT username FROM resgistration WHERE username = '".$username."'";
            $run_multiple = mysql_query( $find_multiple ) or die ( mysql_error() );

            if( mysql_num_rows( $run_multiple ) == 0 ) {
                $password= md5($password);

                mysql_query( "INSERT INTO `resgistration` (`username`, `password`) VALUES ('".$username."', '".$password."')" ) or die(mysql_error());
                echo "You have succesfully registered!";
            } else {
                echo "That username has already beed used" ;
            } 

        } # endelse: empty password or username
    } # endif: registered
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
<html>
    <head>
        <tilte>Registration</title>
    </head>

    <body>
        <h1>Register</h1>
        <form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post'>
            Username: <input type='text' name='username'/></br>
            password: <input type='password' name='password'/></br>
            <input type='hidden' name='hide' value='1' />
            <input type='submit' value='Register' name='register'/>
        </form> 
    </body>
</html>
Rohit
  • 403
  • 3
  • 15
  • Parse error: syntax error, unexpected end of file in C:\Users\User\l\htdocs\register.php on line 42 – dean012 Nov 28 '13 at 08:37
  • can you give the code where getting syntax error??? – Rohit Nov 28 '13 at 08:49
  • mysql_query( "INSERT INTO `register` (`username`, `password`) VALUES ('".$username."', '".$password."')" ) (die(mysql_error()); echo "You have succesfully registered!"; – dean012 Nov 28 '13 at 08:52
  • and i tired mysql_query( "INSERT INTO `register` (`username`, `password`) VALUES ('".$username."', '".$password."')" ) or die(mysql_error()); echo "You have succesfully registered!"; – dean012 Nov 28 '13 at 08:52
  • can you check my second code? – dean012 Nov 28 '13 at 10:47
  • Notice: Undefined index: username in C:\Users\User\l\htdocs\register.php on line 12 Notice: Undefined index: password in C:\Users\User\l\htdocs\register.php on line 13 – dean012 Nov 28 '13 at 10:48
0

At:

mysql_query("INSERT INTO register SET Username='$Username', Password='$Pasword' ") or die(mysql_error());

You missed an s at $Pasword

Also you are using capital letters and when you declare them, you dont use capital letters...

So use:

mysql_query("INSERT INTO register SET Username='$username', Password='$password' ") or die(mysql_error());

You also have:

 $password= md5($password)

Which should be:

 $password= md5($password);

That would fix your error:

Parse error: syntax error, unexpected 'mysql_query'

Also Rohit is right about the:

1) Replace

if(!username || !$password)

With

if(!$username || !$password)

By the way. Don't use mysql...

EDIT:

Now that I notice it, you aren't closing the

else{

at:

if(!username || !$password){
    echo "One of the fields are empty";
    }else{

AND phpcoder is right about the:

echo "You have succesfully registered!":

Should be

echo "You have succesfully registered!";

I didn't notice it myself.

2nd EDIT:

This was the answer on his problem he had before. He updated the question with the mistakes gone now.

Loko
  • 6,539
  • 14
  • 50
  • 78
  • i done that can you check my eddited code? i got Notice: Undefined index: username in C:\Users\User\l\htdocs\register.php on line 12 Notice: Undefined index: password in C:\Users\User\l\htdocs\register.php on line 13 – dean012 Nov 28 '13 at 10:42
  • @dean012 I've had the same problem once and it was something with the mysql real escape string as I recall, but can't remember anymore. It looks normal. – Loko Nov 28 '13 at 10:54