Registration PHP code doesn't work

0 Ali Khiti · July 31, 2014
Hi guys this code of php registration doens't work for me : When I click the submit buttom it just send me to the exact same page...
Here's the code of register.php


<?php
$page_title = "Test";
include 'header.php';

?>

<?php
$submit= @$_POST['submit'];

$fn = strip_tags(@$_POST['fname']);
$un = strip_tags(@$_POST['username']);
$em = strip_tags(@$_POST['email']);
$em2 = strip_tags(@$_POST['email2']);
$pswd = strip_tags(@$_POST['password']);
$pswd2 = strip_tags(@$_POST['password2']);
$d = date("Y-m-d");
if ($submit) {
if ($em==$em2) {

$u_check = mysql_query("SELECT username FROM users WHERE username='$un'");

$check = mysql_num_rows($u_check);

$e_check = mysql_query("SELECT email FROM users WHERE email='$em'");

$email_check = mysql_num_rows($e_check);
if ($check == 0) {
if ($email_check == 0) {

if ($fn&&$un&&$em&&$em2&&$pswd&&$pswd2) {

if ($pswd==$pswd2) {

if (strlen($un)>25||strlen($fn)>25) {
echo "The maximum limit for username/first name/last name is 25 characters!";
}
else
{
if (strlen($pswd)>30||strlen($pswd)<5) {
echo "Your password must be between 5 and 30 characters long!";
}
else
{
$pswd = md5($pswd);
$pswd2 = md5($pswd2);
$query = mysql_query("INSERT INTO users VALUES ('','$un','$fn','$em','$pswd','$d','0')");
die("<h2>Welcome to Welive</h2>Login to your account to get started ...");
}
}
}
else {
echo "Your passwords don't match!";
}
}
else
{
echo "Please fill in all of the fields";
}
}
else
{
echo "Sorry, but it looks like someone has already used that email!";
}
}
else
{
echo "Username already taken ...";
}
}
else {
echo "Your E-mails don't match!";
}
}
?>




<div>
<h2>Register below!</h2>
<div >
<form action="" method="post" accept-charset="utf-8">
<div>
<div>
<input type="text" name="fname" value="" id="email" tabindex="1" placeholder="Your Full Name " />
</div>
<div>
<input type="text" name="username" value="" id="email" tabindex="2" placeholder="Choose a username" />
</div>
<div>
<input type="text" name="email" value="" id="email" tabindex="3" placeholder="Enter your email adress" />
</div>
<div>
<input type="text" name="email2" value="" id="email" tabindex="4" placeholder="Comfirm your email adress" />
</div>
<div>
<input type="password" name="password" value="" id="password" tabindex="5" placeholder="Choose a password" />
</div>
<div>
<input type="password" name="password2" value="" id="password" tabindex="6" placeholder="Comfirm your password" />
</div>
</div>

<div>
<button type="submit" name="submit" class="submit" tabindex="7">Register</button>
</div>
</form>
</div>
</div>

<?php include 'html/footer.php'; ?>

Post a Reply

Replies

- page 1
Oldest  Newest  Rating
+2 YuKusawa Ayoub · August 1, 2014
Your Code Is Correct , You have a Just One ERror HEre :
<button type="submit" name="submit" class="submit" tabindex="7">Register</button> 

Try To Change it To be

<input type="submit" name="submit" class="submit" tabindex="7" Value="Register" />

and it Will be Works Good ;)
+1 pratt 15 · July 31, 2014
You have written,
<form action="" method="post" accept-charset="utf-8">

You have to put the name in action="example.php" ,if your php code is in the same page of index.php then include this in your form,

<form action="index.php" method="post" accept-charset="utf-8">
0 JOhaL jaTT · August 2, 2014
Hey @ Ali Khiti   i have solved  the error just copy my code again and sorry for reply late. 
and also add "id" in your database it mast be auto_increment and primary key. 
0 Ali Khiti · August 3, 2014
Thank you guys so much
0 YuKusawa Ayoub · August 3, 2014
You're Welcome ^^
0 JOhaL jaTT · July 31, 2014
Here is the index.html

i did not test it if there is any problem then reply me..
just create table named user with four field. fname , username , email  and  password.
<html>
<head>
<style>
#test > form > input{
left:115px;
position:absolute;
}
</style>
<title> TEST </title>
</head>
<div id="test">
<h2>Register below!</h2>
<form action="active.php" method="post" accept-charset="utf-8">

First Name <input type="text" name="fname" value="" id="email" tabindex="1" placeholder="Your Full Name " />
<br />
<br />
User Name<input type="text" name="username" value="" id="email" tabindex="2" placeholder="Choose a username" />
<br />
<br />
E-Mail<input type="text" name="email" value="" id="email" tabindex="3" placeholder="Enter your email adress" />
<br />
<br />
Password<input type="password" name="password" value="" id="password" tabindex="5" placeholder="Choose a password" />
<br />
<br />
Match Password <input type="password" name="password2" value="" id="password" tabindex="6" placeholder="Comfirm your password" />
<br />
<br />
<input type="submit" name="submit" value="Register" tabindex="7" />

</form>
</div>
</html>

<------------------------------------------------------------>
and Here is the active.php


<?php
if( isset($_POST['fname'])){
// CONNECT TO THE DATABASE
include_once("db_conx.php");

$fname = $_POST['fname'];

$uname = preg_replace('#[^a-z0-9]#i', '', $_POST['username']); 

$email = mysqli_real_escape_string($db_conx, $_POST['email']);

$password = $_POST['password'];

$password2 = $_POST['password2'];

$sql = "SELECT id FROM users WHERE username='$uname' LIMIT 1";
    $query = mysqli_query($db_conx, $sql); 

$u_check = mysqli_num_rows($query);

// -------------------------------------------

$sql = "SELECT id FROM users WHERE email='$email' LIMIT 1";

    $query = mysqli_query($db_conx, $sql); 
$e_check = mysqli_num_rows($query);

// FORM DATA ERROR HANDLING

if($fname == "" || $uname == "" || $email == "" || $password == "" || $password2 == ""){

echo "The form submission is missing values.";
        exit();
}
else if ($password != $password2){
echo "password did not match ";
}
else if (strlen($password) < 3 || strlen($password) > 16){
echo" password must be between 3 and 16 characters ";
}
 else if ($u_check > 0){ 
        echo "The username you entered is alreay taken";
        exit();

else if ($e_check > 0){ 
        echo "That email address is already in use in the system";
        exit();

else if (strlen($uname) < 3 || strlen($uname) > 16) {
        echo "Username must be between 3 and 16 characters ";
        exit(); 
    } 
else if (is_numeric($uname[0])) {
        echo 'Username cannot begin with a number';
        exit();
    }
 else {
    // END FORM DATA ERROR HANDLING
   // Begin Insertion of data into the database
   // Hash the password and apply your own mysterious unique salt
$cryptpass = crypt($password);
// Add user info into the database table for the main site table
$sql = "INSERT INTO users (fname username, email, password)       
       VALUES('$fname','$uname','$email','$password')";
$query = mysqli_query($db_conx, $sql); 
}
}
?>
0 Ali Khiti · July 31, 2014
It still doens't work Pratt...
0 JOhaL jaTT · August 1, 2014
it is not a big problem mate you active you form in index.html just changed some things like 


rename index.html to index.php

<form action="<?php $_SERVER['PHP_SELF']?>"    method="POST"> and copy paste all active.php code in index.php all right hope it will help you. 
0 Ali Khiti · August 1, 2014
Sorry I didn't know how to do it, here's the code:
0 Ali Khiti · August 1, 2014

<?php
$page_title = "Test";
include 'header.php';

?>

<?php
$submit= @$_POST['submit'];

$fn = strip_tags(@$_POST['fname']);
$un = strip_tags(@$_POST['username']);
$em = strip_tags(@$_POST['email']);
$em2 = strip_tags(@$_POST['email2']);
$pswd = strip_tags(@$_POST['password']);
$pswd2 = strip_tags(@$_POST['password2']);
$d = date("Y-m-d");
if ($submit) {
if ($em==$em2) {

$u_check = mysql_query("SELECT username FROM users WHERE username='$un'");

$check = mysql_num_rows($u_check);

$e_check = mysql_query("SELECT email FROM users WHERE email='$em'");

$email_check = mysql_num_rows($e_check);
if ($check == 0) {
if ($email_check == 0) {

if ($fn&&$un&&$em&&$em2&&$pswd&&$pswd2) {

if ($pswd==$pswd2) {

if (strlen($un)>25||strlen($fn)>25) {
echo "The maximum limit for username/first name/last name is 25 characters!";
}
else
{
if (strlen($pswd)>30||strlen($pswd)<5) {
echo "Your password must be between 5 and 30 characters long!";
}
else
{
$pswd = md5($pswd);
$pswd2 = md5($pswd2);
$query = mysql_query("INSERT INTO users VALUES ('','$un','$fn','$em','$pswd','$d','0')");
die("<h2>Welcome to Welive</h2>Login to your account to get started ...");
}
}
}
else {
echo "Your passwords don't match!";
}
}
else
{
echo "Please fill in all of the fields";
}
}
else
{
echo "Sorry, but it looks like someone has already used that email!";
}
}
else
{
echo "Username already taken ...";
}
}
else {
echo "Your E-mails don't match!";
}
}
?>




<div>
<h2>Register below!</h2>
<div >
<form action="" method="post" accept-charset="utf-8">
<div>
<div>
<input type="text" name="fname" value="" id="email" tabindex="1" placeholder="Your Full Name " />
</div>
<div>
<input type="text" name="username" value="" id="email" tabindex="2" placeholder="Choose a username" />
</div>
<div>
<input type="text" name="email" value="" id="email" tabindex="3" placeholder="Enter your email adress" />
</div>
<div>
<input type="text" name="email2" value="" id="email" tabindex="4" placeholder="Comfirm your email adress" />
</div>
<div>
<input type="password" name="password" value="" id="password" tabindex="5" placeholder="Choose a password" />
</div>
<div>
<input type="password" name="password2" value="" id="password" tabindex="6" placeholder="Comfirm your password" />
</div>
</div>

<div>
<button type="submit" name="submit" class="submit" tabindex="7">Register</button>
</div>
</form>
</div>
</div>

<?php include 'html/footer.php'; ?>
  • 1
  • 2

PHP

107,335 followers
About

Server-side, HTML embedded scripting language used to create dynamic Web pages.

Links
Moderators