Create Php Registration Page easily

I'm trying to do a simple registration page with php and MySql.
<html>
   <head> <title>Process Registration </title>
  
     
  
   </head>
  
<body>
   <table>
      <tr>
     
     
       <table>
        <tr>
         <td>
            <?php
           
            $USERNAME = $_POST['USERNAME'];
            $PASSWORD = $_POST['PASSWORD'];
            $CONFIRMPASSWORD = $_POST['CONFIRMPASSWORD'];
            $FIRSTNAME = $_POST['FIRSTNAME'];
            $SURNAME = $_POST['SURNAME'];
            $ADDRESS1 = $_POST['ADDRESS1'];
            $ADDRESS2 = $_POST['ADDRESS2'];
            $COUNTY = $_POST['COUNTY'];
            $GENDER = $_POST['GENDER'];
            $EMAIL = $_POST['EMAIL'];
            $PHONE = $_POST['PHONE'];
            $MOBILE = $_POST['MOBILE'];
           
            $USERNAME = stripslashes($USERNAME);
            $PASSWORD = stripslashes($PASSWORD);
            $CONFIRMPASSWORD = stripslashes($CONFIRMPASSWORD);
            $FIRSTNAME = stripslashes($FIRSTNAME);
            $SURNAME = stripslashes($SURNAME);
            $ADDRESS1 = stripslashes($ADDRESS1);
            $ADDRESS2 = stripslashes($ADDRESS2);
            $COUNTY = stripslashes($COUNTY);
            $GENDER = stripslashes($GENDER);
            $EMAIL = stripslashes($EMAIL);
            $PHONE = stripslashes($PHONE);
            $MOBILE = stripslashes($MOBILE);
           
            $db="photo";
            $link = mysql_connect('localhost', 'root' , '');
               if (! $link)
               die(mysql_error());
               mysql_select_db($db, $link) or die("Select Error: ".mysql_error());  
        
              
            $USERNAME = mysql_real_escape_string($USERNAME);
            $PASSWORD = mysql_real_escape_string($PASSWORD);
            $CONFIRMPASSWORD = mysql_real_escape_string($CONFIRMPASSWORD);
            $FIRSTNAME = mysql_real_escape_string($FIRSTNAME);
            $SURNAME = mysql_real_escape_string($SURNAME);
            $ADDRESS1 = mysql_real_escape_string($ADDRESS1);
            $ADDRESS2 = mysql_real_escape_string($ADDRESS2);
            $COUNTY = mysql_real_escape_string($COUNTY);
            $GENDER = mysql_real_escape_string($GENDER);
            $EMAIL = mysql_real_escape_string($EMAIL);
            $PHONE = mysql_real_escape_string($PHONE);
            $MOBILE = mysql_real_escape_string($MOBILE);
           
           
              
               if($PASSWORD == $CONFIRMPASSWORD)
              
               {
                  $result=mysql_query
                 
                  ("INSERT INTO users(username, password, firstname, surname, address1, address2, county, gender, email, phone, mobile)
                     VALUES (
                           '$USERNAME',
                           '".md5($PASSWORD)."',
                           '$FIRSTNAME'.
                           '$SURNAME',
                           '$ADDRESS1',
                           '$ADDRESS2',
                           '$COUNTY',
                           '$GENDER',
                           '$EMAIL',
                           '$PHONE',
                           '$MOBILE')")
                  or die("Insert Error: ".mysql_error());
                  mysql_close($link);
              
            echo " Successfully Registared";
           
            ?>
           
      <br />
         <form method="POST" action="index.php">
        
            <input type="submit" value="Next">
         </form>
        
            <?php
            }
            else
            {
               echo " Passwords do not match";
              
            ?>
           
            <br />
           
         <form method="POST" action="registration.php">
        
            <input type="submit" value="Retry">
         </form>
        
         <br />
        
            <?php
            }
            ?>
        
         </td>
            </tr>
               </table>
                     </td>
                        </tr>
                           </table>
   </body>
</html>
Got Insert Error: You have an error in your SQL syntax; Then i tried below

$query = "INSERT INTO users(username, password, firstname, surname, address1, address2, county, gender, email, phone, mobile)
                     VALUES (
                           '$USERNAME',
                           '".md5($PASSWORD)."',
                           '$FIRSTNAME'.
                           '$SURNAME',
                           '$ADDRESS1',
                           '$ADDRESS2',
                           '$COUNTY',
                           '$GENDER',
                           '$EMAIL',
                           '$PHONE',
                           '$MOBILE')"

echo $query;
If you store a query in a variable before passing it to the mysql_query function, you can debug your query more easily by echoing it on the page, instead of just going by the error message. And because it is an easily missed error, here goes:
"INSERT INTO users(username, password, firstname, surname, address1, address2, county, gender, email, phone, mobile)
                     VALUES (
                           '$USERNAME',
                           '".md5($PASSWORD)."',
                           '$FIRSTNAME'. //Double check this line :)
                           '$SURNAME',
                           '$ADDRESS1',
                           '$ADDRESS2',
                           '$COUNTY',
                           '$GENDER',
                           '$EMAIL',
                           '$PHONE',
                           '$MOBILE')"

Share this

Related Posts

There was an error in this gadget