Hi guys, I'm creating a register page for my website. I have got things sorted now, when i try and test the page and try and register a user the data is not been inserted into the database

I'm not getting any error messages at all so I dont know what is going wrong

This is the connection code

<?php 
mysql_connect ("localhost", "root", ""); 
mysql_select_db ("tut"); 



?> 

This is the code

<!DOCTYPE html>
<html>
    <head>
        <title>Richard Hemmings  </title>
        <meta name="viewpoint" content="width=device-width, intail-scale=1.0">
        <link href = "css/bootstrap.min.css"rel = "stylesheet">
        <link href = "css/stylesheet.css" rel = "stlesheet">
    </head>
    <body>
        <div class = "navbar navbar-inverse navbar-static-top">
            <div class = "contrainer">
<?php
include('inc/header.php');
require('connection_db.php'); 


if(isset($_POST ['submit'])){
   // Peform the berification of the nation 
   $email1 = $_POST['email1']; 
   $email2 = $_POST['email2']; 
   $pass1 = $_POST['pass1']; 
   $pass2 = $_POST['pass2']; 
   if($email1 == $email2) {
        if($pass1 == $pass2) {

            $name = mysql_escape_string($_POST['name']);
            $lname = mysql_escape_string($_POST['lname']);
            $uname = mysql_escape_string($_POST['uname']);
            $email1 = mysql_escape_string($email1);
            $email2 = mysql_escape_string($email2);
            $pass1 = mysql_escape_string($pass1);
            $pass2 = mysql_escape_string($pass2);

            $pass1 = md5 ($pass1);


            mysql_query("INSERT INTO 'users' ('id, 'name', 'lname'; 'email', 'pass',) VALUES (NULL, '@$name', '$lname', '$uname', '$email1', '$pass1',) ") or die(mysql_error());


        }else{ 
                echo "sorry, your passwords do not match. <br />"; 
                exit(); 
        }
    }else{
        echo "Sorry your email's do not match, please try again<br /><";
    }
}else{ 
       echo $form =   <<<EOT
                <form action='register.php' method="POST">
                    First Name: <input type="text" name="name" /><br />
                    Last Name: <input type="text" name="lname" /><br />
                    Username: <input type="text" name="uname" /><br />
                    Email: <input type="text" name="email1" /><br />
                    Confirm Email: <imput type="text" name="email2" /><br />
                    Password: <input type="password" name"pass1" /><br />
                    Confirm Password <input type="password" name="pass2" /><br />
                    <input type="submit" value="Register" name="Submit" /><br />
EOT;
//echo $form;
// the preceding line must have NO leading white-space of any kind
}
?>
        <div class = "navbar navbar-default navbar-fixed-bottom"> 
                <div class = "container"> 
                    <P class = "navbar-text">Site build and belongs to Richard Hemmings (C) 2015</P> 
                </div> 
                </div>
       <script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script><script src = "js/bootstrap/js" ></script>
        </body>
        </html>

Any help would be brilliant

Recommended Answers

All 9 Replies

Member Avatar for diafol

Any help would be brilliant

Well, stop using deprecated code. Use PDO or mysqli.

Have you tried changing...

if(isset($_POST['submit'])){

...to...

if(isset($_POST['Submit'])){

...or change...

name="Submit" 

...to...

name="submit" 

...on the button?

Could be that simple? As "Submit" does not = "submit"

morning people sorry i was asleep last night

I have made some changes and this is how the code looks now

<!DOCTYPE html> 
<html> 
    <head> 
        <title>Richard Hemmings  </title> 
        <meta name="viewpoint" content="width=device-width, intail-scale=1.0"> 
        <link href = "css/bootstrap.min.css"rel = "stylesheet"> 
        <link href = "css/stylesheet.css" rel = "stlesheet"> 
    </head> 
    <body> 
        <div class = "navbar navbar-inverse navbar-static-top"> 
            <div class = "container"> 
             <div class = "navbar navbar-default navbar-fixed-bottom">  
                <div class = "container">  
                    <P class = "navbar-text">Site build and belongs to Richard Hemmings (C) 2015</P>  
                </div>  
                </div> 
       <script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script><script src = "js/bootstrap/js" ></script> 
        </body> 
        </html> 
<?php 
include('inc/header.php'); 
require('connection_db.php');  


if(isset($_POST ['submit'])){ 
   // Peform the berification of the nation  
   $email1 = $_POST['email1'];  

   $pass1 = $_POST['pass1'];  
   $pass2 = $_POST['pass2'];  
   if($email1 == $email2) { 
        if($pass1 == $pass2) { 

            $name = mysql_escape_string($_POST['name']); 
            $lname = mysql_escape_string($_POST['lname']); 
            $uname = mysql_escape_string($_POST['uname']); 
            $email1 = mysql_escape_string($email1); 

            $pass1 = mysql_escape_string($pass1); 
            $pass2 = mysql_escape_string($pass2); 

            $pass1 = md5 ($pass1); 


            mysql_query("INSERT INTO 'users' ('id, 'name', 'lname'; 'email', 'pass',) VALUES (NULL, '@$name', '$lname', '$uname', '$email1', '$pass1',) ") or die(mysql_error()); 


        }else{  
                echo "sorry, your passwords do not match. <br />";  
                exit();  
        } 
    }else{ 
        echo "Sorry your email's do not match, please try again<br /><"; 
    } 
}else{  
       echo $form =   <<<EOT 
                <form action='register.php' method="POST"> 
                    First Name: <input type="text" name="name" /><br /> 
                    Last Name: <input type="text" name="lname" /><br /> 
                    Username: <input type="text" name="uname" /><br /> 
                    Email: <input type="text" name="email1" /><br /> 
                    Password: <input type="password" name ="pass1" /><br /> 
                    Confirm Password <input type="password" name="pass2" /><br /> 
                    <input type="submit" value="Register" name="submit" /><br /> 
EOT; 
//echo $form; 
// the preceding line must have NO leading white-space of any kind 
} 
?>

I'm now getting the following

Notice: Undefined variable: email2 in C:\xampp\htdocs\register.php on line 31
Sorry your email's do not match, please try again
<

mysql_query("INSERT INTO 'users' ('id, 'name', 'lname'; 'email', 'pass',) VALUES (NULL, '@$name', '$lname', '$uname', '$email1', '$pass1',) ") or die(mysql_error());

This is also invalid. It should be with backticks for the column names, and without semi-colons and the comma at the end. And no @:

mysql_query("INSERT INTO `users` (`id`, `name`, `lname`, `email`, `pass`) VALUES (NULL, '$name', '$lname', '$uname', '$email1', '$pass1') ") or die(mysql_error());

I have changed that but still getting the following error message :

Notice: Undefined variable: email2 in C:\xampp\htdocs\register.php on line 31
Sorry your email's do not match, please try again
<

no ive changed it again since then sorry i'm tripping myself up....

this is the code now as it stands

<!DOCTYPE html>
<html>
    <head>
        <title>Richard Hemmings  </title>
        <meta name="viewpoint" content="width=device-width, intail-scale=1.0">
        <link href = "css/bootstrap.min.css"rel = "stylesheet">
        <link href = "css/stylesheet.css" rel = "stlesheet">
    </head>
    <body>
        <div class = "navbar navbar-inverse navbar-static-top">
            <div class = "container">
             <div class = "navbar navbar-default navbar-fixed-bottom"> 
                <div class = "container"> 
                    <P class = "navbar-text">Site build and belongs to Richard Hemmings (C) 2015</P> 
                </div> 
                </div>
       <script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script><script src = "js/bootstrap/js" ></script>
        </body>
        </html>
<?php
include('inc/header.php');
require('connection_db.php'); 


if(isset($_POST ['submit'])){
   // Peform the berification of the nation 
   $email1 = $_POST['email1']; 

   $pass1 = $_POST['pass1']; 
   $pass2 = $_POST['pass2']; 

        if($pass1 == $pass2) {

            $name = mysql_escape_string($_POST['name']);
            $lname = mysql_escape_string($_POST['lname']);
            $uname = mysql_escape_string($_POST['uname']);
            $email1 = mysql_escape_string($email1);

            $pass1 = mysql_escape_string($pass1);
            $pass2 = mysql_escape_string($pass2);

            $pass1 = md5 ($pass1);


        mysql_query("INSERT INTO `users` (`id`, `name`, `lname`, `email`, `pass`) VALUES (NULL, '$name', '$lname', '$uname', '$email1', '$pass1') ") or die(mysql_error());


        }else{ 
                echo "sorry, your passwords do not match. <br />"; 
                exit(); 
        }
    }else{
        echo "Sorry your email's do not match, please try again<br /><";
    }
{ 
       echo $form =   <<<EOT
                <form action='register.php' method="POST">
                    First Name: <input type="text" name="name" /><br />
                    Last Name: <input type="text" name="lname" /><br />
                    Username: <input type="text" name="uname" /><br />
                    Email: <input type="text" name="email1" /><br />
                    Password: <input type="password" name ="pass1" /><br />
                    Confirm Password <input type="password" name="pass2" /><br />
                    <input type="submit" value="Register" name="submit" /><br />
EOT;
//echo $form;
// the preceding line must have NO leading white-space of any kind
}
?>

I'm now getting the following

Column count doesn't match value count at row 1

You are inserting 6 values into the table with only 5 columns..I think you missed out uname in the insert statement.

thanks for that i managed to sort it and when i did there was a mis-spelling in my database and it all works fine now thank you so much for the help its much appreicated, i can now get on with the log in form and script to let users log into the site

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.