Jump to content

Register form


BasiM

Recommended Posts

Hello.
 
Hope someone can help me.
 
I have created a simple user registration form. The user is required to insert data into the fields and insert a username and password.
The server will check in the database if the username and password don't already exist. If the username and password are already in the database it will print out a message that username and password already exist. 
 
If username and password don't exist it will run the INSERT statement and display a user successful message.
 
My issue/problem. There is no error message printed. When I run the script it says ''User successful''. When I run the script again entering the same username and password, it prints the ''User successful message'' yet no data is inserted into the database.
 
Hope someone can help
 
Thanx
 
 
 
<?php
/*
 * author :basetsanamnl0@gmail.com
 *
 *
 *
 */
include 'connection.php';
 
    if(isset ($_POST['name'] ) && isset ($_POST['surname']) && isset ($_POST[ 'id_number']) && isset ($_POST[ 'contact_number'])&& isset ($_POST[ 'job_id'])&& isset ($_POST[ 'username'])&& isset ($_POST['password'])) // getting the values from the post
    {
 
    $connection = new createConnection(); // creating connection
 
    $connect = $connection->connectToDatabase(); // connect to database
 
    $connection->selectDatabase(); // select database
     
// escape sql injection
  $name = mysql_real_escape_string($_POST['name']); 
 $surname =mysql_real_escape_string($_POST['surname']);
$id_number = mysql_real_escape_string($_POST['id_number']);
$contact_number = mysql_real_escape_string($_POST['contact_number']);
$job_id = mysql_real_escape_string($_POST['job_id']);
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
 
      $query=mysql_query("SELECT * FROM `medionline`.`employees` WHERE username='$username' AND password= '$password'"); 
// Check if the username and password already exist in the database
 
if (mysql_num_rows($query) > 0) { 
 
echo "Username and password already exist!";
 
 
}  else {
// execute the insert query
    mysql_query("INSERT INTO `medionline`.`employees`(name,surname,id_number,contact_number,job_id,username, password) VALUES     ('$name','$surname','$id_number','$contact_number','$job_id','$username','$password')"); // query for insert data
 
}
 
   echo ("User registration Successfull"); 
   $connection->closeConnection(); // closing the connection
    }
 
    else
    {
        echo "Error occured!"; // display error message
    }
 
 
?>

Link to comment
Share on other sites

You output the success message in all cases

    if (mysql_num_rows($query) > 0)
        {
        echo "Username and password already exist!";
        }
    else
        {
        // execute the insert query
        mysql_query ("INSERT INTO `medionline`.`employees`(name,surname,id_number,contact_number,job_id,username, password) VALUES     ('$name','$surname','$id_number','$contact_number','$job_id','$username','$password')"); // query for insert data
        }

    echo ("User registration Successfull");
    $connection->closeConnection(); // closing the connection

Easier to see when you use indentation

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.