Jump to content

PHP Sign Up Form


Jason12356789

Recommended Posts

Hi,

 

Im having trouble with my simple sign up form. I think the form code is fine as that is pretty easy but its the process part im having trouble with. Here is the connect to database code

 

    <?php
start_session();
include "./includes/connect.php";
include "./includes/lists.php";
include "./includes/functions.php";

?>

 

and here is the process code that im stuck on

 

<?php
        $username = $_POST['liusername'];
        $password = $_POST['lipassword'];
        $emailAddress = $_POST['liemail'];
        $firstName = $_POST['lifirstname'];
        $surname = $_POST['lisurname'];
        $DOB = $_POST['lidob'];
        $city = $_POST['licity'];
        $sports = $_POST['lisports'];
 
        $query = "INSERT INTO `user`
        (user_username, user_password, user_email, user_firstname, user_surname, user_dob, user_city)
        
        VALUES ('$username', '$password', '$email', '$firstName', '$surname', '$DOB', '$city')";
        
        
        
            $result = mysql_query($query);
            if($result) {
            echo "User Created Successfully.";

?>

 

Thanks!!! :)

 

Link to comment
Share on other sites

So what is the issue? Any errors? if so post them here.

 

The only problem I see is you are not validating/sanitizing your users input and you left of the closing brace for the if statement }

if($result) {
            echo "User Created Successfully.";
} // <-- this is missing
Link to comment
Share on other sites

While im here, once i create the user and log in ive set it to display, 'login has been sucessful' but as soon as i click on another link it logs back out again. Any ideas on how i get it to permenatly stay logged in once ive logged in, so even if i click on another page, the user still stays loggin in? ::)

Link to comment
Share on other sites

While im here, once i create the user and log in ive set it to display, 'login has been sucessful' but as soon as i click on another link it logs back out again. Any ideas on how i get it to permenatly stay logged in once ive logged in, so even if i click on another page, the user still stays loggin in? ::)

 

You could use PHP sessions:

http://www.php.net/manual/en/intro.session.php

Link to comment
Share on other sites

While im here, once i create the user and log in ive set it to display, 'login has been sucessful' but as soon as i click on another link it logs back out again. Any ideas on how i get it to permenatly stay logged in once ive logged in, so even if i click on another page, the user still stays loggin in? ::)

You need to implement sessions. So on every page start the session ( session_start() )

 

Upon successfull login you set a logged in session token

$_SESSION['logged_in'] = true;

Now on any page the requires the user to be logged in you check for this token. If it is not set, or is not set to true then you'd redirect the user to the login page. So you'd have code like this for at the top of your restricted pages

<?php
session_start();

if(!isset($_SESSION['logged_in']) || (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] !== true))
{
    // redirect user to the login page
    header('Location: login.php');
    exit;
}

// display restricted content
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.