PHP server error

Discussion in 'PHP' started by webber09, Jan 22, 2011.

  1. #1
    hi all, i have been making a php mysql login, however it is throwing up a 500 server error and i have no clue why, here's the code:

    <?
    if (isset($_POST['submitted'])) {
    	
    	$errors = array();
    	
    	if (empty($_POST['first_name'])) {
    		$errors[] = 'You forgot to enter your First Name.';
    	} else {
    		$fn = trim($_POST['first_name']);
    	}
    	
    	if (empty($_POST['last_name'])) {
    		$errors[] = 'You forgot to enter your Last Name.';
    	} else {
    		$ln = trim($_POST['last_name']);
    	}
    	
    	if (empty($_POST['email'])) {
    		$errors[] = 'You forgot to enter your email address.';
    	} else {
    		$e = trim($_POST['email']);
    	}
    	
    	if (!empty($_POST['pass1'])) {
    		if ($_POST['pass1'] != $_POST['pass2']) {
    			$errors[] = 'Your password did not match the confirmed password.';
    		} else {
    			$p = trim($_POST[['pass1']);
    		}
    	} else {
    		$errors[] = 'Your forgot to enter your password.';
    	}
    	
    	if (empty($errors)) {
    		require_once ('mysqli_connect.php');
    		$q = "insert into users (first_name, last_name, email, pass, registration_date) values ('$fn', '$ln', '$e', sha1('$p'), now() )";
    		$r = @mysqli_query ($dbc, $q);
    		if ($r) {
    			echo '<h1>Thank you!</h1>
    			<p>You are now registered</p>';
    		} else {
    			echo '<h1>System error</h1>
    			<p>You could not be registered due to a system error</p>';
    			echo '<p>' . mysqli_error($dbc) . '<br /><br /> Query: ' . $q . '</p>';
    		}
    		mysqli_close();
    		exit();
    	} else { 
    	echo '<h1>Error!</h1>
    	<p>The following errors occurred:<br />';
    	foreach ($errors as $msg) {
    		echo " - $msg<br />\n";
    	}
    	echo '</p><p>Please try again.</p>';
    	}
    }
    ?>
    <h1>Register</h1>
    <form action="register.php" method="post">
      <p>First Name:
        <input type="text" name="first_name" size="15" maxlength="20" value="<? if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" />
      </p>
      <p> Last Name:
        <input type="text" name="last_name" size="15" maxlength="40" value="<? if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" />
      </p>
      <p> Email Address:
        <input type="text" name="email" size="20" maxlength="80" value="<? if (isset($_POST['email'])) echo $_POST['email']; ?>" />
      </p>
      <p>Password:
        <input type="password" name="pass1" size="10" maxlength="20" />
      </p>
      <p>Confirm Password:
        <input type="password" name="pass2" size="10" maxlength="20" />
      </p>
      <p>
        <input type="submit" name="submit" value="Register" />
      </p>
      <input type="hidden" name="submitted" value="true" />
    </form>
    PHP:
    can anyone see a reason why this may be?
     
    webber09, Jan 22, 2011 IP
  2. Darkimmortal

    Darkimmortal Active Member

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    86
    #2
    $p = trim($_POST[['pass1']);
    PHP:
    Extra [ there ;)

    Also your server is not configured correctly if it is throwing a 500 error rather than telling you where the error is.
     
    Darkimmortal, Jan 22, 2011 IP
  3. webber09

    webber09 Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    #3
    OMG :mad: silly mistake... ty v much
     
    webber09, Jan 22, 2011 IP
  4. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #4
    but it isn't only mistake webber, it can't just start to work if you deleted that [ :D
    It's server-side problem, not PHP. try to remove/rename .htaccess and it should work
     
    G3n3s!s, Jan 22, 2011 IP
  5. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #5
    If PHP hasn't been configured to properly handle errors, it could result in an internal server error.
     
    Alex Roxon, Jan 22, 2011 IP
  6. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #6
    internal server error = config error. It can't parse part of .htaccess or so on
     
    G3n3s!s, Jan 22, 2011 IP
  7. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #7
    A lot more than .htaccess can cause internal server errors. It could be an error within the PHP configuration file (php.ini), for example, which is what I was hinting at.
     
    Alex Roxon, Jan 22, 2011 IP
  8. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #8
    yep, sorry. Whole configuration of PHP can reult in ISO (500)
     
    G3n3s!s, Jan 22, 2011 IP
  9. webber09

    webber09 Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    #9
    i have no .htaccess for this. all seams to work as soon as i got rid of the extra [ and it is working as intended
     
    webber09, Jan 22, 2011 IP
  10. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #10
    webber I think it's impossible. What do you use as web host? localhost? Or some webhosting?
     
    G3n3s!s, Jan 22, 2011 IP
  11. webber09

    webber09 Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    #11
    it is hosted with birch hosting and the mysql is on the same server i guess. all the details are in the mysqli_connect.php which is used in the require_once function
     
    webber09, Jan 22, 2011 IP
  12. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #12
    yes I saw it ;)
    Umm, maybe screwed php.ini configuration but I am not sure. However, it doesn't matter if it works! :)
     
    G3n3s!s, Jan 22, 2011 IP
  13. webber09

    webber09 Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    #13
    well its adding to the mysql table fine so it appears so
     
    webber09, Jan 22, 2011 IP