Skip to main content
wilkister
Known Participant
June 7, 2020
Answered

My PHP registration form does nothing when i click sign up

  • June 7, 2020
  • 2 replies
  • 1012 views

I am new to php and and my sql. I am trying to create a registration form for users of my website. I was able to successfully create a send message form, but this time i want to creat a registration form, i am stuck, my form does nothing when i enter the required data. I have already created my Database using my sql in my Hostgator server. I also created users table withh all the columns required.

Here is my HTML

<!DOCTYPE html>
<html>
<head>
<title> User Registration in PHP </title>
<link rel="stylesheet" type="text/css" href="file:///C|/wamp64/www/useraccounts/css/bootstrap.min.css">
</head>
<body>

<div>
<form action="file:///C|/wamp64/www/useraccounts/Registration.php" method="post">
<div class="container">
<div class="row">
<div class="col-sm-3">

<h1> Registration </h1>
<p> Fill up the Form with Correct values</p>
<hr class="mb-3">
<label for="firstname"><b>First Name</b></label>
<input class="form-control" type="text" name="firstname" required>

<label for="lastname"><b>Last Name</b></label>
<input class="form-control" type="text" name="lastname" required>

<label for="email"><b>Email Address</b></label>
<input class="form-control" type="email" name="email" required>

<label for="phonenumber"><b>Phone Number</b></label>
<input class="form-control" type="text" name="phonenumber" required>

<label for="password"><b>Password</b></label>
<input class="form-control" type="password" name="password" required>
<hr class="mb-3">
<input class="btn btn-primary" type="submit" name="create" value="Sign Up">
</div>
</div>
</div>
</form>

</div>
</body>

</html>

 

 

HERE is my php

 


<?php
if(isset($_POST['create'])){
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$phonenumer = $_POST['phonenumber'];
$password = $_POST['password'];

echo $firstname . " " . $lastname ." " . $email . " " . $phonenumer . " " . $password;

}
?>

    This topic has been closed for replies.
    Correct answer

    Your form action is not correct, neither is the link to the Bootstrap css file. Correct those and see what happens

    2 replies

    Nancy OShea
    Community Expert
    June 7, 2020

    A critical first step is to define your local site folder BEFORE you begin a project (Site > New Site).  

     

    Right now, your assets are pointing to FILES on your computer HD instead of your site folder.    See screenshot.

     

     

    Nancy O'Shea— Product User, Community Expert & Moderator
    wilkister
    wilkisterAuthor
    Known Participant
    June 7, 2020

    Got it.

    Correct answer
    June 7, 2020

    Your form action is not correct, neither is the link to the Bootstrap css file. Correct those and see what happens

    wilkister
    wilkisterAuthor
    Known Participant
    June 7, 2020

    i fixed the issues you sent me, however i went a different route..I now have this errow when i click register. 

    Fatal error:uncaught error:call to undefined mysql_real_escape_string()..here is my code

    <?php
     session_start();
     
    // connect to databse
    $db = mysqli_connect("localhost", "dbnameuser","password","dbname");
    
    if (isset($_POST['register_btn'])){
    	session_start();
    	$username = mysql_real_escape_string($_POST['username']);
    	$email = mysql_real_escape_string($_POST['email']);
    	$password = mysql_real_escape_string($_POST['password']);
    	$password2 = mysql_real_escape_string($_POST['password2']);
    	
    	if ($password == $password2){
    		//create user
    		$password =md5($password);// hash password before storing for security purposes
    		$sql = "INSERT INTO users(username,email,password) VALUES('$username','$email,'$password')";
    		mysqli_query($db, $sql);
    		$_SESSION['message'] = "You are now logged in";
    		$_SESSION['username'] = $username;
    		header("location: home.php"); //redirect to home page
    		
    	}else{
    		$_SESSION['message'] = "The two passwords do not match";
    	}
    	}
    
    ?>

     

     

    June 8, 2020

    You are getting that error because you are mixing and mathcing mysqli(improved) with the old mysql extention, which you cannot do.

     

    I use the mysqli 'Object Oriented' method to connect to the database, rather than the 'Procedural ' method which you are currently using:

     

    $db = new mysqli('localhost' , 'dbusername' , 'dbpassword , 'dbname');

     

    Then use real_escape_string :

    $username = $db->real_escape_string($_POST['username']);

     

    You also should not be using md5 to encrypt your password you should be using the php inbuilt functions 'password_hash' and 'password_verify':

     

    $password = $db->real_escape_string($_POST['password']);

    //hash the password

    $userPassword = password_hash($password, PASSWORD_DEFAULT);

    //Insert $userPassword into database - you know how to do that?

     

    Then when someone signs in you request their username and password:

     

    $username = $db->real_escape_string($_POST['username']);
    $password = $db->real_escape_string($_POST['password']);

     

    // Query the database for the username
    $getUserDetails = $db->query("SELECT * FROM users WHERE username = '$username'") or die($db->error);
    // count no of results
    $numRows = $getUserDetails->num_rows;
    // assign user details  to a variable
    $getUserDetails = $getUserDetails->fetch_assoc();

    //verify the password - $getUserDetails['password'] below is the column in the database where the hashed password is stored

    if(password_verify($password, $getUserDetails['password'] )){
    echo "Correct details";
    }
    else {
    echo "Incorrect details";
    }