Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Registration Page: Not adding user to database

Featured Replies

Hi can anyone please have a look at my code and see where I am going wrong please.

I followed a step by step tutorial and no matter what I do when I register it just refuses to add my data in phpMyAdmin. Can you also please provide me with how I can add the box for the "Confirm Password"

 

Thanks

 

Register.php

<div id="formWrap">
     <h1>Register</h1>
     <div id="form">
       <form action="regprocess.php" method="post" id = "register_form" >
         <div class="row">
           <div class="label">Username</div>
           <!-- end .label -->
           <div class="input">
             <input type="text" id="username" class="detail" name="username"/>
           </div>
           <!-- end .input -->
           <div class="context">Only letters and numbers are allowed</div>
           <!-- end .context --> 
         </div>
         <!-- end .row -->
         <div class="row">
           <div class="label">Email</div>
           <!-- end .label -->
           <div class="input">
             <input type="email" id="email" class="detail" name="email"/>
           </div>
           <!-- end .input -->
           <div class="context">We will not share your email with anyone or spam you with messages either</div>
           <!-- end .context --> 
         </div>
         <!-- end .row -->
         <div class = "row">
           <div class = "label">First Name</div>
           <!--end.label-->
           <div class = "input">
             <input type = "text" id = "fullname" class ="detail" name ="fname"/>
           </div>
           <!-- end .input -->
           <div class="context">e.g. Richard John</div>
           <!-- end .context --> 
         </div>
         <!-- end .row -->
         <div class="row">
           <div class="label">Last Name</div>
           <!-- end .label -->
           <div class="input">
             <input type="text" id="lastname" class="detail" name="lname"/>
           </div>
           <!-- end .input -->
           <div class="context">Wakefield</div>
           <!-- end .context --> 
         </div>
         <!-- end .row -->
         <div class="row">
           <div class="label">Password</div>
           <!-- end .label -->
           <div class="input">
             <input type="password" id="pass1" class="detail" name="password"/>
           </div>
           <!-- end .input -->
           <div class="context">Must be between 6 and 20 characters long, with at least one lowercase letter, one uppercase letter, and one number</div>
           <!-- end .context --> 
         </div>
         <!-- end .row -->
         <div class="submit">
           <input type="submit" id="submit" name="submit" value="Register"/>
         </div>
         <!-- end .submit -->
       </form>
       <!-- end #form --> 
     </div>
   </div>

 

regprocess.php

<?php
include "config.php";

$username = $_POST['username'];
$email = $_POST['email'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$password = md5($_POST['password']); 

$insert = 'INSERT into users(username, email, fname, lname, password) VALUES("'.$username.'","'.$email.'","'.$fname.'","'.$lname.'","'.$password.'")';

mysql_query($insert);

?>

 

config.php

<?php

$localhost = "localhost";
$dbuser = "root";
$dbpass = "admin";
$dbname = "mystore";

$connect = mysql_connect($localhost, $dbuser, $dbname);
mysql_select_db("$dbname", $connect);

?> 

post-39567-0-65652100-1339359239_thumb.jpg

  • Author

What message do you get?

Hi thanks for your reply. I dont get an error message at all. Once I click register it goes to the regprocess.php but that is just blank.

I think this is the problem: VALUES("'.$username.'","'.$email.'","'.$fname.'","'.$lname.'","'.$password.'");

I always did like: VALUES("$username","$email","$fname","$lname","$password");

 

I'm not sure, but this always worked for me ... ;)

I think this is the problem: VALUES("'.$username.'","'.$email.'","'.$fname.'","'.$lname.'","'.$password.'");

I always did like: VALUES("$username","$email","$fname","$lname","$password");

 

I'm not sure, but this always worked for me ... ;)

 

You mean that query looking like this:

 

 

VALUES("username", "password", "name")

 

Should look like this:

 

VALUES(username,password,name)

 

But I still think its best to make it look like this:

 

VALUES('username', 'password', 'name')

 

 

 

 

But yet again its all almost same. So try this query then:

 


$insert = "INSERT INTO `users` (`username`, `email`, `fname`, `lname`, `password`) VALUES('{$username}', '{$email}', '{$fname}', '{$lname}', '{$password}')";

mysql_query($insert);

 

 

In your config.php you need to refer to the password in your $connect statement

 

$connect = mysql_connect($localhost, $dbuser, $dbpass);
mysql_select_db("$dbname", $connect);

 

Its worth running your mysql statements in a mysql editor or phpmyadmin as it will point out errors with an error message which can be more useful than just getting a blank page.

In your config.php you need to refer to the password in your $connect statement

 

$connect = mysql_connect($localhost, $dbuser, $dbpass);
mysql_select_db("$dbname", $connect);

 

Its worth running your mysql statements in a mysql editor or phpmyadmin as it will point out errors with an error message which can be more useful than just getting a blank page.

or he can just use mysql_error like this

 

mysql_query($insert) or die(mysql_error());

 

you really should also think about using some mysql injection prevention with mysql_real_escape_string

Keep in mind just like the <label for="something">, form elements are identified with $_POST[] by their 'id', not their 'name'.. To keep things simple, I normally keep the input name and id the same.

 

In your form you've got:

<input type = "text" id = "fullname" class ="detail" name ="fname"/>

 

While in regprocess.php, you've got:

$fname = $_POST['fname'];

 

This is looking for a value posted from an element like (take note of 'id'):

<input type = "text" id = "fname" class ="detail" name ="fname"/>

 

If you're using Chrome, open Chrome Inspector, select the 'Network' tab, submit the form and check for a POST entry to 'regprocess.php'. In there you'll be able to see the names and values of the entries that are posted when the form is submitted.

 

Edit: On a slightly different note, and not to be rude, but you really don't need so many comments in your code... It actually makes it more difficult to read. :) Better use of indents and white space would be much easier to follow when you come back to this code in 6 months' time, for example:

<div id="formWrap">
   <h1>Register</h1>
   <div id="form">
       <form action="regprocess.php" method="post" id="register_form" >
           <div class="row">
               <div class="label">
                   <label for="username">Username</label>
               </div>
               <div class="input">
                   <input type="text" id="username" class="detail" name="username"/>
               </div>
               <div class="context">Only letters and numbers are allowed</div>
           </div>

           <div class="row">
               <div class="label">Email</div>
               etc.....

Edited by ZaLiTH

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.