0
<center></center>
<form name="registration_form" method="post" action="register.php" 
    onsubmit="return Validate();">
<table border="0" align=center>

<tr>
<td><font size=5><center>Name: </center></font></td><td><input type="text" name="names"></td>
</tr>

<tr>
<td><font size=5><center>Email: </center></font></td><td><input type="text" name="email"></td>
</tr>

<tr>
<td><font size=5><center>Username: </center></font></td><td><input type="text" name="username"></td>
</tr>

<tr>
<td><font size=5><center>Password: </center></font></td><td><input type="password" name="password"></td>
</tr>

<tr>
<td><font size=5><center>Password Confirmation: </center></font></td><td><input type="password" name="password_confirmation"></td>
</tr>

<tr>
<td><font size=5><center>Phone Number: </center></font></td><td><input type="text" name="phone_number"></td>
</tr>

<tr>
<td><font size=5><center>Click to Register </center></font></td><td><input type="submit" value="Register"></td>
</tr>
</table>
</form>
</center>
<br>




<?php
session_start();
include ('config.php');

$names = $_POST["names"];
$email = $_POST["email"];
$phone_number = $_POST["phone_number"];
$username = md5($_POST["username"]);
$password = md5($_POST["password"]);

$checkuser = mysql_query("SELECT email FROM users WHERE email='$email'"); 
$email_exist = mysql_num_rows($checkuser);


if($email_exist > 0){

    unset($email);
    include 'registration_form.php';
echo "<script>alert('Duplicate entry on email: ".$_POST['email'].".     Please use another email.')</script>";    

    exit();
}


$checkuser = mysql_query("SELECT username FROM users WHERE username='$username'"); 
$username_exist = mysql_num_rows($checkuser);

if($username_exist > 0){


    unset($username);
    include 'registration_form.php';
    echo "<script>alert('Duplicate entry on username: ".$_POST['username'].".     Please use another username.')</script>";

    exit();
}

$sql = "INSERT INTO users (id_user, names, email, phone_number, username, password)  VALUES ('','$names', '$email', '$phone_number', '$username', '$password')";
$result = mysql_query($sql,$con);


if(mysql_error())
{

}
    else {

}
if(!$result){
    die('Error: '. mysql_error());
}
else
{
include ("success_user.php");
echo "<script>User $names Succesfully Added!</script>";
}
?>

Guys how will i make it interactively warns when the password confirmation will not match. and check if null field it won't save. Thanks in advance guys.

4
Contributors
8
Replies
12
Views
4 Years
Discussion Span
Last Post by opawix
0

@opawix

Guys how will i make it interactively warns when the password confirmation will not match. and check if null field it won't save. Thanks in advance guys.

Read this:

http://www.code-sucks.com/code/php/template.php?tutorial=php_login.php

This code came from the link above but I post it here so you can get a general idea how it works:

//Checking to make for sure the username and password match.  
if (($usergroup == 1)) {  
if  ($pass_return['password'] == $pass_final){  
session_start();  
$_SESSION['loggedin'] = 1; //Setting session for security purposes.  
$_SESSION['user'] = $user;  
$_SESSION['usergroup'] = $usergroup;  
header( 'Location: main.php');  
} else {  
  echo "Incorrect password.<br>";  
}  
}else{  
 echo "You do not have permissions to use this function. Please try logging in again.";  
} 

Just read the whole article and used whatever code you need to plug it in your own code.
If you are curious where to start it's on line 65 on your own code

0

sorry sir, my concern is when you register and confirming the password on the form it will alert when you retype it unmatch. and it will not save into database if you have empty field.

0

There's no need to include javascript for displaying a message if you're running php on the server anyway. I'm assuming that your page is setup so that the form sends to itself? It's unclear as to where your php code is running - is it really below the form? If so why the include 'registration_form.php' - which I assume is the same as the html form. Unclear.

0

the code was actually separated in other php file. i just join both codes so you could easily view.

0

@diafol

There's no need to include javascript for displaying a message if you're running php on the server anyway.

I didn't notice there was a javascript in there until you mention it. I think it was near midnight so I misread it as a table.

0

You have two options -
1. Use Javascript to verify that both passwords match (and the rest of the form is completed correctly) before the form is submitted. Your script appears to be configured that way looking at this line:
<form name="registration_form" method="post" action="register.php" onsubmit="return Validate();">
2.Use PHP to check both passwords once the form has been sent and echo a relevant message to the user if there is a problem with the data submitted.

1

I used js for conditions in form, i just want to make it php pure. thanks for your share.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.