Jump to content

Help


Joshua F

Recommended Posts

Hello,

I am having a problem with this code I am using.

<?php
    //Start session
    session_start();
    
    //Include database connection details
    require_once('config.php');
    
    //Array to store validation errors
    $errmsg_arr = array();
    
    //Validation error flag
    $errflag = false;
    
    //Connect to mysql server
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if(!$link) {
        die('Failed to connect to server: ' . mysql_error());
    }
    
    //Select database
    $db = mysql_select_db(DB_DATABASE);
    if(!$db) {
        die("Unable to select database");
    }
    
    //Function to sanitize values received from the form. Prevents SQL injection
    function clean($str) {
        $str = @trim($str);
        if(get_magic_quotes_gpc()) {
            $str = stripslashes($str);
        }
        return mysql_real_escape_string($str);
    }
    
    //Input Validations
    if(empty($_POST['username'])) {
        $errmsg_arr[] = 'Username Missing';
        $errflag = true;
    }
    if(empty($_POST['password'])) {
        $errmsg_arr[] = 'Password Missing';
        $errflag = true;
    }
    if(empty($_POST['cpassword'])) {
        $errmsg_arr[] = 'Confirm Password Missing';
        $errflag = true;
    }
    if(empty($_POST['email'])) {
        $errmsg_arr[] = 'Email Address Missing';
        $errflag = true;
    }
    if(empty($_POST['pin'])) {
        $errmsg_arr[] = 'Your 4 Digit Pin is Missing';
        $errflag = true;
    }
    if(empty($_POST['key'])) {
        $errmsg_arr[] = 'Your 25 Digit Beta Key is Missing';
        $errflag = true;
    }
    if( strcmp($_POST['password'], $_POST['cpassword']) != 0 ) {
        $errmsg_arr[] = 'Your passwords do not match!';
        $errflag = true;
    }
    
    //Check for duplicate Usernames
    if($username != '') {
        $qry = "SELECT * FROM users WHERE username='$_POST['username']'";
        $result = mysql_query($qry);
        if($result) {
            if(mysql_num_rows($result) > 0) {
                $errmsg_arr[] = 'Username already in use';
                $errflag = true;
            }
            @mysql_free_result($result);
        } else {
            die("Query failed");
        }
    }
    
    //Check for duplicate Beta Keys
    if($key != '') {
        $qry = "SELECT * FROM beta_keys WHERE keys_used='$_POST['key']'";
        $result = mysql_query($qry);
        if($result) {
            if(mysql_num_rows($result) > 0) {
                $errmsg_arr[] = 'This Beta Key has already been used';
                $errflag = true;
            }
            @mysql_free_result($result);
        }
        else {
            die("Query failed");
        }
    }
    
    //Check for duplicate Emails
    if($email != '') {
        $qry = "SELECT * FROM users WHERE email='$_POST['email']'";
        $result = mysql_query($qry);
        if($result) {
            if(mysql_num_rows($result) > 0) {
                $errmsg_arr[] = 'Email already in use';
                $errflag = true;
            }
            @mysql_free_result($result);
        }
        else {
            die("Query failed");
        }
    }
    
    //If there are input validations, redirect back to the registration form
    if($errflag) {
        $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
        session_write_close();
        header("location: register.php");
        exit();
    }

    //Create INSERT query
    mysql_query("INSERT INTO users (username, password, email, pin, key) VALUES ('". clean($_POST['username'] ."', '". clean($_POST['password']) ."', '". clean($_POST['email']) ."', '". clean($_POST['pin']) ."', '". clean($_POST['key']) ."')");
    
    //Updated Beta Keys
    mysql_query("UPDATE beta_keys SET keys_new='', keys_used='$_POST['key']' WHERE keys_new=$_POST['key']'") or die(mysql_error());
    
    //Check whether the query was successful or not
    if($result) {
        header("location: register-success.php");
        exit();
    }else {
        die("Query failed");
    }
?>

 

Error

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\xampp\htdocs\server status\register-auth2.php on line 67

 

Please look through it, and see if you see anything wrong.

Link to comment
https://forums.phpfreaks.com/topic/217976-help/
Share on other sites

  Quote

Change:

$qry = "SELECT * FROM users WHERE username='$_POST['username']'";

 

To:

$qry = "SELECT * FROM users WHERE username='".$_POST['username']."'";

 

Take care with double/single quotes. With your original code, PHP would have seen $_POST[ and then been cut off by the single quote.

 

I got it, I'm using a different code now. Started fresh.

Link to comment
https://forums.phpfreaks.com/topic/217976-help/#findComment-1131250
Share on other sites

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.