Click here to Skip to main content
15,913,487 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i try to improve it this time so it can become more readable. and may be i mismatch {} this. so thats why i am writing a hint after every { closing in which line, and after this } started at this line, it will make it more clear.

thx
and its showing error in the line 39, and the error is
Parse error: syntax error, unexpected T_ELSE in


1.
PHP
<?php
2. session_start();
3. include ("connect.php");
4. include ("html_codes.php");

5. if (isset ($_POST ['submit'])) { closing at line 49m before php closing statement.
6.    $error = array ();

7. if (empty ($_POST ['username'])) { closing at line 9
8.    $error [] = 'please enter a username.';
9.    } started at line 8
10.    else if (ctype_alnum($_POST['username'])) { closing at line 12
11.        $error[]= 'username must consist of letters and numbers only';
12.            }started at line 10

13. if (empty ($_POST ['email'])) {closing at line 15
14.    $error [] = 'please enter your email.';
15.    }started at line 13

16.    else if  (preg_match ("/^ ([a-zA-Z0]) +([a-zA-Z0-9_-])+([a-zA-Z0-\._-]+)+$/", $_POST ['email']))17. { closing at line 20
18.        $email=  mysql_real_escape_string($_POST ['email']);
19.        $error[]='your e-mail adress is invalid';
20.    } started at line 17

21.    if (empty ($_POST ['password'])) { closing at line 23
22.        $error[]='please enter your password';
23.    } started at line 21

24.    else { closing at line 38
25.        if (empty ($error)){ closing at 28
26.        $result =mysql_query ("SELECT * FROM users WHERE email = '$email' OR username = '$username'")
27.        or die (mysql_error());
28.        } started at 28

29.    if (mysql_num_rows ($result)==0){closing at 34
30.    $activation = md5 (uniqid (rand(), true));
31.  $result2 =mysql_query ("INSERT INTO tempusers (user_id,username,email,password,activation) VALUES ('', 32.   '$username', '$email', 'password', '$activation')")
33.            or die (mysql_error());
34.    }started at 29

35. if (!result2) {closing at 37
36. die ( 'could not insert into database:' .mysql_error()); 
37. }

38.    i moved one curly bracket from here to line 

39. else{ closing at 45
40.    $message="To activate your account, please click on this link:\n\n";
41. $message="http://lisa1986.com". '/activae.php?email= '.urlencode ($email). "&key= 
42. $activation";
43. mail($email, 'Registration Confirmation', $message);
44. header ('Location: prompt.php?x=1');
45. }started at 39
45a.  } this is the curly bracket which i moved from line 38
46. else {closing at 46b
46a. header ('Location: prompt.php?x=2');
46b. } new curly bracket
46c. <pre>$error_message = '<span class = "error">';

46b.
foreach ($error as $key=> $values){

47. $error_message='</span><br/><br/>';
48. }started at 46
49. }started at 5

50. ?>
Posted
Updated 4-Jun-12 22:36pm
v5
Comments
Sergey Alexandrovich Kryukov 4-Jun-12 0:23am    
Did you look at your post after submission? It's not readable!
--SA
arifsuhail 4-Jun-12 1:06am    
yah your are right i am posting it again sorry

thanks by
Mohibur Rashid 4-Jun-12 3:24am    
Please post the Question again, if you can handle the change, someone will fix it for you, may be me.
arifsuhail 4-Jun-12 23:22pm    
i have posted it again, first i try to see weather i am mismatching {}, may be thats the case that's why i write the hint when the curly bracket is opening { closing at this line .......... and when the curly bracket is closed } started it this line. it also help me to check, and the result which i wrote here that where they started and where they closed, i get that result from notepad++, thx
Mohibur Rashid 5-Jun-12 1:48am    
tell me this, did you put those line number at the beginning of the line by yourself? by they why this thread says solved?

Even though, I didn't see your code. but it is very much possible that you are mixing up with curly bracket. try to found the combination. Use Notepad++. this is an excellent tool for coding php. it will also help you to find out bracket miss management.

[adding]
Look at your line 35, an if started. at line 38 there is closing from the line 24, it is a closing of an else

then another else started. and if condition cannot have two else statement. if the next else is related with your line 35 if then the closing bracket at line 38 will move down.
 
Share this answer
 
v2
PHP
<?php
session_start();
include ("includes/connect.php");
include ("html_codes.php");

if (isset ($_POST ['submit'])) {
    $error = array ();

if (empty ($_POST ['username'])) {
    $error [] = 'please enter a username.';
    }
    else if (ctype_alnum($_POST['username'])) {
        $username = $_POST ['username'];
    }else{
        $error[]= 'username must consist of letters and numbers only';
            }
 if (empty ($_POST ['email'])) {
    $error [] = 'please enter your email.';
    }

    else if  (preg_match ("/^ ([a-zA-Z0]) +([a-zA-Z0-9_-])+([a-zA-Z0-\._-]+)+$/", $_POST ['email'])){
        $email=  mysql_real_escape_string($_POST ['email']);
        $error[]='your e-mail adress is invalid';
    }

    if (empty ($_POST ['password'])) {
        $error[]='please enter your password';
    }
    else{ $password=  mysql_real_escape_string($_POST ['password']);
    }

        if (empty ($error)){
        $result =mysql_query ("SELECT * FROM users WHERE email = '$email' OR username = '$username'")
        or die (mysql_error());
        if (mysql_num_rows ($result)==0){
    $activation = md5 (uniqid (rand(), true));
  $result2 =mysql_query ("INSERT INTO tempusers (user_id,username,email,password,activation) VALUES ('', '$username', '$email', 'password', '$activation')")
            or die (mysql_error());
    }
if (!result2) {
die ( 'could not insert into database:' .mysql_error());
}

else{
    $message="To activate your account, please click on this link:\n\n";
$message="http://lisa1986.com". '/activae.php?email= '.urlencode ($email). "&key= $activation";
mail($email, 'Registration Confirmation', $message);
header ('Location: prompt.php?x=1');
}
        }


else {
    header ('Location: prompt.php?x=2');
}
$error_message = '<span class = "error">';
foreach ($error as $key=> $values){
    $error_message='</span><br/><br/>';
    }


}


?>
 
Share this answer
 
Comments
Mohibur Rashid 5-Jun-12 4:59am    
you dont need to post your code again if it works, and definitly not as answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900