Jump to content

HTTP 500 Internal Server Error


gkjr1

Recommended Posts

I have no idea why it's doing it. I know I'm missing something, but everything looks right to me. When you submit the registration form it just does the error, and properties say its the process page, so this code below. Sorry posting it all, I'm just not sure period.

 

<?php
require('connect.php');

//check all the posted info
function getInfo() {
$error = array();
$fname = validateFirstname($_POST['fname']);
$lname = validateLastname($_POST['lname']);
$uname = validateUsername($_POST['uname']);
$email = validateEmail($_POST['email']);
$password = validatePass($_POST['password1'], $_POST['password2']);
$phone = validatePhone($_POST['phone']);

//check for errors
error();
}
function validateFirstname($str) {
//This allows just alpha characters and must be at least 2 characters.
if (preg_match('/^[a-zA-Z0-9]{2,}$/',$str)) {
	return  preg_match('/^[a-zA-Z0-9]{2,}$/',$str);
} else {
	$error[] = 'Please enter a valid first name!';
}

}
function validateLastname($str) {
//This allows just alpha characters and must be at least 2 characters.
if (preg_match('/^[a-zA-Z0-9]{2,}$/',$str)) {
	return  mysql_real_escape_string($str);
} else {
	$error[] = 'Please enter a valid last name!';
} 

}
function validateUsername($str) {
//connect to database
$link = mysql_connect($db_host, $db_user, $db_pass); 
if (!$link) {
    	die('Could not connect: ' . mysql_error());
}

mysql_select_db($db_name);
//pull usernames to make sure new is unique
$sql = "SELECT username FROM users WHERE username = '".$str."'";
if ($sql == "") {
	//This allows just alphanumeric characters and must be 4 - 15 characters.
	if (preg_match('/^[a-zA-Z0-9]{4,15}$/',$str)) {
		return mysql_real_escape_string($str); 
	} else {
		$error[] = 'Please enter a valid user name!';
	}
} else {
	$error[] = 'This user name is already registered!';
}
}
function validateEmail($str) {
//connect to database
$link = mysql_connect($db_host, $db_user, $db_pass); 
if (!$link) {
    	die('Could not connect: ' . mysql_error());
}

mysql_select_db($db_name);
//pull usernames to make sure new is unique
$sql = "SELECT email FROM users WHERE email = '".$str."'";
if ($sql == "") {
	if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/",$str)) {
    		return mysql_real_escape_string($str); 
	}else{
		$error[] = 'Please enter a valid email!';   
	}
} else {
	$error[] = 'This email is already registered!';
}
}
function validatePass($str, $str2) {
//This allows just alphanumeric characters and must be 6-15 characters.
if ($str == $str2) {
	if (preg_match('/^[a-zA-Z0-9]{6,15}$/',$str)) {
		return md5(mysql_real_escape_string($str)); 
	} else {
		$error[] = 'Please enter a valid password!';
	}
} else {
	$error[] = 'Passwords do not match!';
}
}
function validatePhone($str) {
//This allows just alpha characters and must be at least 2 characters.
if (preg_match('/^[0-9]{0,11}$/',$str)) {
	return  mysql_real_escape_string($str);
} else {
	$error[] = 'Please enter a valid phone number!';
} 

}
function error() {
if ($error[] == '') {
	addInfo();
} else {
	echo "<a href='javascript: history.go(-1)'><-- Go Back</a><br>";
	echo $error[];
}
}
function addInfo() {
//setcookie("site_user", $Name, time() + 31536000, "/"); 
//setcookie("site_pass", $Password, time() + 31536000, "/"); 

//Connect to database from here
$link = mysql_connect($db_host, $db_user, $db_pass); 
if (!$link) {
    	die('Could not connect: ' . mysql_error());
}
//activation link
$a = md5(uniqid(rand(), true));
//select the database | Change the name of database from here
mysql_select_db($db_name);
$sql="INSERT INTO users (firstname,lastname,email,username,password,phone,active,ip,rank,acctcreated) VALUES ('$fname','$lname','$uname',$email','$lastpass','$phone',$a','$ip','$rank',NOW())";
}

// Send the email:
$message = " To activate your account, please click on this link:\n\n";
$message .= WEBSITE_URL . '/activate.php?email=' . urlencode($Email) . "&key=$activation";
mail($Email, 'Registration Confirmation', $message, 'From:'.EMAIL);

// Flush the buffered output.
// Finish the page:
echo '<div class="success">Thank you for registering! A confirmation email has been sent to ' . $Email .' Please click on the Activation Link to Activate your account </div>';


?>

Link to comment
https://forums.phpfreaks.com/topic/259688-http-500-internal-server-error/
Share on other sites

usually it is in a "Logs" directory where php is installed.

 

One thing I see is your trying to make a class but have an invalid structure.

 

class MyClass{
public $error = array();
public function validateFirstname($str){
	if (preg_match('/^[a-zA-Z0-9]{2,}$/',$str)) {
		return  preg_match('/^[a-zA-Z0-9]{2,}$/',$str);
	} else {
		$this->error[] = 'Please enter a valid first name!';
	}
}
}

<?php
if (isset($_POST['submitted'])) {
//This allows just alpha characters and must be at least 2 characters.
if (preg_match('/^[a-zA-Z0-9]{2,}$/',$_POST['fname'])) {
	$fname = mysql_real_escape_string($_POST['fname']);
} else {
	$error[] = 'Please enter a valid first name!';
}

//This allows just alpha characters and must be at least 2 characters.
if (preg_match('/^[a-zA-Z0-9]{2,}$/',$_POST['lname'])) {
	$lname = mysql_real_escape_string($_POST['lname']);
} else {
	$error[] = 'Please enter a valid last name!';
} 

//This allows just alphanumeric characters and must be 4 - 15 characters.
if (preg_match('/^[a-zA-Z0-9]{4,15}$/',$_POST['uname'])) {
	$uname = $_POST['uname']; 
} else {
	$error[] = 'Please enter a valid user name!';
}

//check email
if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/",$_POST['email'])) {
    	$email = mysql_real_escape_string($_POST['email']); 
}else{
	$error[] = 'Please enter a valid email!';   
}

//This allows just alphanumeric characters and must be 6-15 characters.
if ($_POST['password1'] == $_POST['password2']) {
	if (preg_match('/^[a-zA-Z0-9]{6,15}$/',$_POST['password1'])) {
		$lastpass = md5($_POST['password1']); 
	} else {
		$error[] = 'Please enter a valid password!';
	}
} else {
	$error[] = 'Passwords do not match!';
}

//This allows just alpha characters and must be at least 2 characters.
if (preg_match('/^[0-9]{0,11}$/',$_POST['phone'])) {
	$phone = mysql_real_escape_string($_POST['phone']);
} else {
	$error[] = 'Please enter a valid phone number!';
}
echo $lname .",". $fname .",". $uname .",". $email .",". $lastpass .",". $phone;
}

 

Even then throws the code. Please help someone its been hours of me trying to find the problem...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.