0
intaxing.in/register.php

or(website probably don't work)

test.intaxing.in/register.php

You can look here for the actual working page that did not record anything it just asks again & again for the password I install an app in this order.

sudo apt install apache2  php7.3  mariadb-server  mariadb-client php-mysql phpMyAdmin

Command updated......

Please let me know if I do wrong somewhere. Or the issue is because of MD5. The same code is working in Window Xampp I use PHP mostly. But if anybody finds an issue I am very helpful to you.

I correct code on PHP 7.3 so now phpMyAdmin doesn't show any error. Install again and again but the result never changes. Working on the latest version of everything.

<?php   
ob_start();
session_start();
    
$timezone = date_default_timezone_set("Asia/Kolkata");

$con = mysqli_connect("localhost", "punee", "4927","intax");

if(mysqli_connect_errno()) {
    echo "Failed to connect: " . mysqli_connect_errno();
}



class Account {

    private $con;
    private $errorArray;
    
    public function __construct($con){
        $this->con = $con;
        $this->errorArray = array();
    }
public function login($un, $pw){
    $pw = md5($pw);
    $query = mysqli_query($this->con, "SELECT * FROM users WHERE username='$un' AND password='$pw'");
    if(mysqli_num_rows($query) == 1) {
        return true;
    }
    else {
        array_push($this->errorArray, Constants::$loginfailed );
        return false;
    }
}

public function Register($un, $fn, $ln, $em, $pw, $pw1, $ph) {
    $this->validateUsername($un);
    $this->validatefirstname($fn);
    $this->validatelastname($ln);
    $this->ValidateEmail($em);
    $this->ValidatePasswrod($pw, $pw1);
    $this->ValidatePhone($ph);
    if(empty($this->errorArray) == true){
    //insert into db
        return $this->insertUserDetails($un, $fn, $ln, $em, $pw, $ph);
        }
    else{
        return false;
    }
}

public function getError($error) {
    if(!in_array($error, $this->errorArray)) {
        $error = "";
    }
    return "<span class='errorMessage'>$error</span>";
} 

private function insertUserDetails($un, $fn, $ln, $em, $pw, $ph){
    $encryptedPw = md5($pw);
    $profilePic = "include/assets/profile-pic/index.png";
    $date = date("Y-m-d");
    
    $result = mysqli_query($this->con, "INSERT INTO users VALUES ('', '$un', '$fn', '$ln', '$em', '$date' , '$encryptedPw', '$profilePic' , '$ph')");
    return $result;
}

    

private function validateUsername($un){
    if(strlen($un) >25 || strlen($un) <5) {
        array_push($this->errorArray, Constants::$useridCharacters );
        return;
    }
    
    $checkUsernameQurey = mysqli_query($this->con,"SELECT username FROM users WHERE username='$un'");
    if(mysqli_num_rows($checkUsernameQurey) != 0){
        array_push($this->errorArray, Constants::$UsernameTaken);
        return;
    }
}
    ///Database Validation but data not prepare


private function validatefirstname($fn){
    if(strlen($fn) >15 || strlen($fn) <2) {
        array_push($this->errorArray, Constants::$firstnameCharacters);
        return;
    }
}

private function validatelastname($ln){
    if(strlen($ln) >15 || strlen($ln) <2) {
        array_push($this->errorArray,Constants::$lastnameCharacters);
        return;
    }
}

private function ValidateEmail($em){
    if(!filter_var($em, FILTER_VALIDATE_EMAIL)) {
        array_push($this->errorArray,Constants::$emailinvalid);
        return; 
    }
    
    $checkEmailQurey = mysqli_query($this->con,"SELECT Emailid FROM users WHERE Emailid='$em'");
    if(mysqli_num_rows($checkEmailQurey) != 0){
        array_push($this->errorArray, Constants::$emailTaken);
        return;
    }
///check for the email as database prepare
}

private function ValidatePasswrod($pw, $pw1){
    if($pw != $pw1){
        array_push($this->errorArray,Constants::$passwordsDoNotMatch);
        return;
    }
    if(preg_match('/[^A-Za-z0-9]/',$pw)){

    array_push($this->errorArray,Constants::$passwrodNotAlphaNumeric);
    return;
    }
    if(strlen($pw) >10 || strlen($pw) <6) {
    array_push($this->errorArray, Constants::$passwordsCharacters);
    return;
        
    }
}

private function ValidatePhone($ph) {
    if(strlen($ph) != 10) {
        array_push($this->errorArray,Constants::$phoneCharacters);
        return;
    }
}

    }


class Constants {

public static $passwordsDoNotMatch = " Your Password don't match";
public static $passwrodNotAlphaNumeric = " Your password can only contain numbers and letters";
public static $passwordsCharacters = " Your Password must be between 6 and 10 characters";
public static $emailinvalid = " Enter a Vaild Email";
public static $useridCharacters = " Your username must be between 5 and 25 characters";
public static $firstnameCharacters = " Your First Name must be between 2 and 15 characters";
public static $lastnameCharacters = " Your Last Name must be between 2 and 15 characters";
public static $phoneCharacters = " Your Mobile Number Should be 10 Digit";
public static $UsernameTaken = " Your Username is already taken";
public static $emailTaken = " Your Email ID is already taken";
public static $loginfailed = "Email or Password Incorrect";
  

    }
$account = new Account($con);

    function sanitizeFormPassword($inputText){
$inputText = strip_tags($inputText);
    return $inputText;
    }

    function sanitizeFormUsername($inputText) {
$inputText = strip_tags($inputText);
$inputText = str_replace(" ","",$inputText);
    return $inputText;
     }
     function sanitizeFormstring($inputText){
$inputText = strip_tags($inputText);
$inputText = str_replace(" ","",$inputText);
$inputText = ucfirst(strtolower($inputText));
return $inputText;
      }
     if(isset($_POST['signupbutton']))
{
    $username = sanitizeFormUsername($_POST['username']);
    $firstname = sanitizeFormstring($_POST['firstname']);
    $lastname = sanitizeFormstring($_POST['lastname']);
    $Email = sanitizeFormstring($_POST['Email']);
    $Password = sanitizeFormPassword($_POST['Password']);
    $Password1 = sanitizeFormPassword($_POST['Password1']);
    $Phone = sanitizeFormstring($_POST['Phone']);
    
    $wasSuccesfull= $account->register($username, $firstname, $lastname, $Email, $Password, $Password1, $Phone);
    if($wasSuccesfull == true){
        $_SESSION['userLoggedIn']=$username;
        
    header("Location: index.php");
    }
}
      /**
      * @param $name
        */
     function getInputValue($name){
    if(isset ($_POST[$name])){
    echo $_POST[$name];
    }
}
?>
   <html>
   <head>
<tittle> <h2> Register Yourself It just  takes some time </h2></tittle>
    </head>
   <body>
<div id ="inputContainer">
    <form id="loginForm" action="register.php" method="POST">
        <h2> Create Your Account</h2>
        <p>
            <?php echo $account->getError(Constants::$useridCharacters);?> 
            <?php echo $account->getError(Constants::$UsernameTaken);?>
            <label  for="username">Username</label> 
            <input id="username" name="username" type="text" placeholder="e.g. Puneetxp" Value="<?php echo getInputValue('username');?>"    required>
        </p>
        <p>
            <?php echo $account->getError(Constants::$firstnameCharacters);?>
            <label for="firstname">First Name</label>
            <input id="firstname" name="firstname" type="text" placeholder="e.g. Puneet" Value="<?php echo getInputValue('firstname');?>" required>
        </p>
        <p>
            <?php echo $account->getError(Constants::$lastnameCharacters);?>
            <label  for="lastname">Last Name</label>
            <input id="lastname" name="lastname" type="text" placeholder="e.g. Sharma" Value="<?php echo getInputValue('lastname');?>">
        </p>
        <p>
            <?php echo $account->getError(Constants::$emailinvalid);?>
            <?php echo $account->getError(Constants::$emailTaken);?>
            <label for="Email">  Email</label>
            <input  id="Email" name="Email" type="Email" Value="<?php echo getInputValue('Email');?>" required>
        </p>
        <p>
            <?php echo $account->getError(Constants::$passwordsDoNotMatch);?>
            <?php echo $account->getError(Constants::$passwrodNotAlphaNumeric);?>
            <?php echo $account->getError(Constants::$passwordsCharacters);?>
            <label for="Possword"> Password</label>
            <input id="Password" name="Password" type="password"  required>
        </p>
        
        <p> 
            <label for="Possword1">Confirm Password</label>
            <input id="Password1" name="Password1" type="password" required>
        </p>
        
        <p>
            <?php echo $account->getError(Constants::$phoneCharacters);?>
            <label for="Phone"> Phone </label>
            <input id="Phone" name="Phone" type="tel"  maxlength="10" Value="<?php echo getInputValue('Phone');?>" required>
        </p>
        <button type="submit" name="signupbutton">Sign UP</button>
    </form>
</div>  

Code Updated as per bob suggestion let hope this time my question is right.

5
  • 2
    I don't see the code that didn't work. Please edit your question to include the code; please don't use a link to some other page.
    – Bob Brown
    Mar 26, 2020 at 15:30
  • thanks bob for guidance I will including my full page code for this. Now it may be little big I don't post it. Mar 27, 2020 at 9:02
  • Your question wasn't "wrong," it's just that a link to PHP only shows the generated HTML and not the code. Without the code, no one can help.
    – Bob Brown
    Mar 27, 2020 at 10:51
  • I haven't spotted the exact problem, but I have looked at the code. If mysqli_query returns FALSE you should be displaying mysqli_error to see what's happening. Without having tested this in my own environment, I suspect that the database insert is failing, causing $wasSuccesfull to be false. You have Value="<?php echo ... for all form fields except the passwords, so the passwords are empty when the form is redisplayed.
    – Bob Brown
    Mar 27, 2020 at 11:39
  • Having looked at your code, I'd like to point out, gently I hope, two things not related to your problem that also need attention. You should really be using MySQL prepared queries to guard against SQL injection. Storing an MD5 hash of a password is only marginally better than storing the plain text. You can find details here: crackstation.net/hashing-security.htm
    – Bob Brown
    Mar 27, 2020 at 11:54

2 Answers 2

0

Instead of the command you used to install the server, try this:

sudo apt install apache2 php7.3 mariadb-server mariadb-client php-mysql phpmyadmin

You cannot install multiple packages by seperating their names with &&.

1
  • thanks I missed MariaDB-client. I only use && for basically mariadb-server && mariadb-client. I install missing but not help may be they need to install in chain. I will be reinstall raspian again. Mar 28, 2020 at 20:05
0
$result = mysqli_query($this->con, "INSERT INTO users VALUES ('', '$un', '$fn', '$ln', '$em', '$date' , '$encryptedPw', '$profilePic' , '$ph')");
    return $result;

there is issue '' work on xammp but not other MySQL sever ,Strange. So change it with

"INSERT INTO `user`(`username`, `firstname`, `lastName`, `Emailid`, `SignUpDate`, `Password`, `profilePic`, `Phone`) VALUES ( '$un', '$fn', '$ln', '$em', '$date' , '$encryptedPw', '$profilePic' , '$ph')";

And it work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.