• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

My PHP registration form does nothing when i click sign up

New Here ,
Jun 07, 2020 Jun 07, 2020

Copy link to clipboard

Copied

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;

}
?>

Views

668

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Jun 07, 2020 Jun 07, 2020

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

Votes

Translate

Translate
Participant ,
Jun 07, 2020 Jun 07, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 07, 2020 Jun 07, 2020

Copy link to clipboard

Copied

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";
	}
	}

?>

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 08, 2020 Jun 08, 2020

Copy link to clipboard

Copied

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";
}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 08, 2020 Jun 08, 2020

Copy link to clipboard

Copied

Osgood-

Next time you post code, use the code insertion icon < / > instead of pasting it directly into a reply.

 

You're working under a new identity that has no prior history.  So everything you do is scrutinized by forum filters.

 

Nancy O'Shea— Product User, Community Expert & Moderator
Alt-Web Design & Publishing ~ Web : Print : Graphics : Media

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 08, 2020 Jun 08, 2020

Copy link to clipboard

Copied

LATEST

I assumed it might be related to that. Strange thing is the post appeared and was there for about 15mins, I updated it twice, then gone before reappearing about 2 hours later.

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 08, 2020 Jun 08, 2020

Copy link to clipboard

Copied

Well I did post an answer to your question only for it to be deleted soon after, for some unknown reason. If you come back and need the answer leave a reply and I'll go through it again.

 

Looks like the post has now been re-instated, over an hour after it appeared then mysteriously disappeared, its above this post.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 07, 2020 Jun 07, 2020

Copy link to clipboard

Copied

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.

 

Local Site in Local Testing ServerLocal Site in Local Testing Server

 

Nancy O'Shea— Product User, Community Expert & Moderator
Alt-Web Design & Publishing ~ Web : Print : Graphics : Media

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 07, 2020 Jun 07, 2020

Copy link to clipboard

Copied

Got it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines