Jump to content

Registration of users


steviedoyle

Recommended Posts

Basically I am developing a simple Sign up and Registration page for my site, but i am having trouble with the registration. When I fill out the form and submit, none of the data is saved to the database. I am using XAMPP and the myphpadmin to create the database for the users, which is working as it should. Login is working fine too. I have attached the file if anyone cares to have a look. I am currently just trying to comment out some of the lines of code to see where the problem lies.

 

register.php

 

 

Thanks in advance for any help, much appriacated.

Link to comment
Share on other sites

Right, I have tidied up your code and formatting a little, moved the form close tag to be after the form elements, changed the way your insert query is run to display a productive error on failure, added field names to the insert that you will need to change to fit with your table, closed a spurious open paragraph tag and removed a couple of random lines of code.  This should, once you make the previously mentioned change, tell you why the insert isn't working.  You are clearly new to this so I'm not going to criticise too much, but your html formatting is seriously bad and needs raising.  You really should learn how to format with CSS instead of using nbsp, paragraphs and tables for layouts. Here's the revised code:

<?php
echo "<h1> Register </h1>"; 
if (isset($_POST['submit'])){
  $submit = $_POST['submit'];  
  //form data
  $fullname = strip_tags($_POST['fullname']);
  $username = strip_tags ($_POST['username']);
  $password = strip_tags($_POST['password']);
  $repeatpassword = strip_tags($_POST['repeatpassword']);
  $date = date ("Y-m-d");
  if ($fullname&&$username&&$password&&$repeatpassword){
    if ($password==$repeatpassword){
     //check char
   if (strlen ($username)>25 ||strlen($fullname)>25){
        echo "max limit for username/fullname are 25 characters"; 
      }
      else{
        //check password length 
        if (strlen ($password)>25 ||strlen($password)<6){
          echo "Password must be between 6 and 25 characters long"; 
        }
        else{
          //register the user
       //open our database 
       $connect = mysql_connect("localhost","root","");
       mysql_select_db("phplogin"); //select database
       $queryreg = "INSERT INTO users (`name`, `username`, `password`, `date`) VALUES ('$name','$username','$password','$date')";
          $insert = mysql_query($queryreg) or die("there was a problem adding the record to the database.<br><br>".$queryreg."<br><br> Caused the following server error".mysql_error()); 
       echo"You are now registered! <a href='Home.php' >Return to home page </a>";
       exit();
       }
      }
    }
    else{
   echo "Your passwords do not match!";  
 }
  }
  else{  
 echo "Please fill in all fields!";
  }
}
?>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="style.css">
<p>
<a href = "home.php">Home</a>  
<a href = "ContactUs.php">ContactUs</a> 
<div align="RIGHT">
<div id="txt"></div>
</div>
<form action="register.php" method="post" >
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<table>
  <tr>
    <td>Your Full name:</td>
<td><input type="text" name="fullname" value="<?php echo $fullname  ?>" </td>
</tr>
<tr>
<td>Choose a username:</td>
<td><input type="text" name="username" value="<?php echo $username  ?>" </td>
</tr>
<tr>
<td>Choose a password:</td>
<td><input type="password" name="password" </td>
</tr>
<tr>
<td>Repeat password:</td>
<td><input type="password" name="repeatpassword" </td>
</tr>
</table>
<p> </p>
<p>
  <input type="submit" value="Register"></p>
  <p> </p>
  <p> </p>
  </form>
</p>
</html>
 

Link to comment
Share on other sites

Cheers mate. Yeah Im fairly new to this, I Started it two years ago for a project (which only last two months) but after that, never really looked at it. Php, I am really new to. Had to pick it up this year for a project, so I am still in the steep learning curve.

Link to comment
Share on other sites

because it's clearly evident that learning basic debugging and database interaction would be far more productive at this stage of the game - for which the mysql connector is significantly easier to manage while it still not actually wrong. Most people find things go smother when they have a solid foundation in the basics before moving on to dealing with intricate aspects such as abstraction layers. 

Link to comment
Share on other sites

But the problem is once they get comfortable with bad practices such as mysql_* some people find it hard  or don't have time to unlearn and relearn new things again

Look at how many code snippets are posted in this board day to day that uses mysql_* in their live site, the horrrrroooorr

Link to comment
Share on other sites

mysql_ is only depreciated, it's not "bad practice", not sanitising form input is bad practice, storing passwords in plain text is bad practice, using select * is bad practice, inserting a null value into an auto inc field is bad practice, using a connection library that has been the defacto standard for years is not.

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.