Question

Im having a little issue with my coding, i keep getting a 500 error when i run this script:

<?php
include_once("../../includes/connect.php");
if (isset($_POST['action']) && $_POST['action'] == "check"){
$email = mysql_real_escape_string(strip-tags($_POST['email']));
$username = mysql_real_escape_string(strip_tags($_POST['username']));

if (strpos($email,"@")!== false){
    $check_email = explode("@",$email);
    if (strpos($check_email[1],".")=== false){
        echo 3;
        exit();
    }
} else {
    echo 3;
    exit();
}
$email_query = mysql_query("SELECT id FROM users WHERE email='$email' LIMIT 1");
if (mysql_num_rows($email_query)== 1){
    //Email already exists
    echo 1;
    exit();
} else {
    $username_query = mysql_query("SELECT username FROM users WHERE username='$username' LIMIT 1");
    if (mysql_num_rows($username_query)== 1){
        //Username already exists
        echo 2;
        exit();
    } else {
        //Everything is fine
        echo 0;
        exit();
    }
}
}
if (isset($_POST['action']) && $_POST['action'] == "register"){
    $username = mysql_real_escape_string(strip_tags($_POST['username']));
    $password = mysql_real_escape_string(strip_tags($_POST['password']));
    $email = mysql_real_escape_string(strip_tags($_POST['email']));

    $activation_code = md5($username.$password);

    $reg_query = mysql_query("INSERT INTO users (username, password, email, activfation_code) VALUES ('$username', '".md5($password)."', '$email', '$activation_code')");
    if ($reg_query){
        //Successfully registered
        $new_userid = mysql_insert_id();
        //Create new users folder
        #mkdir("../users/$new_userid", 0755);
        //Create new users images folder
        #mkdir("../users/$new_userid/images", 0755);
        //Create new users media folder
        #mkdir("../users/$new_userid/media", 0755);

        $to = $email;
        $from = "noreply@atradiesinc.com";
        $subject = "Activate your Account!";

        $message = "<h3>Welcome to Atradies Inc Gaming Community, ".$username."!</h3>
        <p>To complete registration you must verify and activate your account. Click the link below and the magic shall happen.</p>
        <p><a href='http://www.atradiesinc.com/network/?id=$new_userid&activate=$activation_code'>http://www.atradiesinc.com/network/?id=$new_userid&activate=$activation_code</a></p>
        <p>Once your account has been activated, you may login and join in with the community with the details below:<br />
        <strong>Username: </strong>$username<br />
        <strong>Password: </strong><i>Password you supplied on registration</i></p>
        <p>Thank you and enjoy the community!</p>";

        $headers = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= "From: $from\r\nReply-To: $from";
        mail($to, $subject, $message, $headers);

        echo 1;
        exit();

    } else {
        //Registration failed
        echo 0;
        exit();
    }
}

?>

Whats the problem? I cant seem to find any issue with it. Is it the code, or is it the server im trying it out on? Ive tried the Chrome Inspect Element console and it doesnt give any more information then '500 Internal Server Error' on that file.

Thanks!

Was it helpful?

Solution

You have a little typo in the third line:

$email = mysql_real_escape_string(strip-tags($_POST['email']));

should be

$email = mysql_real_escape_string(strip_tags($_POST['email']));

And have a look at the comments, they are quite important.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top