Jason12356789 Posted April 4, 2014 Share Posted April 4, 2014 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 <?phpstart_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!!! Quote Link to comment https://forums.phpfreaks.com/topic/287513-php-sign-up-form/ Share on other sites More sharing options...
Ch0cu3r Posted April 4, 2014 Share Posted April 4, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/287513-php-sign-up-form/#findComment-1474931 Share on other sites More sharing options...
Jason12356789 Posted April 4, 2014 Author Share Posted April 4, 2014 And that was it, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/287513-php-sign-up-form/#findComment-1474932 Share on other sites More sharing options...
Jason12356789 Posted April 4, 2014 Author Share Posted April 4, 2014 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? Quote Link to comment https://forums.phpfreaks.com/topic/287513-php-sign-up-form/#findComment-1474933 Share on other sites More sharing options...
Ch0cu3r Posted April 4, 2014 Share Posted April 4, 2014 Also while you are learning please move away from mysql_* library and instead use PDO or the newer mysqli_* library mysql_* library is deprecated and could soon be removed from future version of PHP. Quote Link to comment https://forums.phpfreaks.com/topic/287513-php-sign-up-form/#findComment-1474934 Share on other sites More sharing options...
cyberRobot Posted April 4, 2014 Share Posted April 4, 2014 (edited) If you haven't done so already, I would recommend looking into the following: mysql_real_escape_string() Validating email addreses: http://www.php.net/manual/en/filter.examples.validation.php Edited April 4, 2014 by cyberRobot Quote Link to comment https://forums.phpfreaks.com/topic/287513-php-sign-up-form/#findComment-1474935 Share on other sites More sharing options...
cyberRobot Posted April 4, 2014 Share Posted April 4, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/287513-php-sign-up-form/#findComment-1474936 Share on other sites More sharing options...
Ch0cu3r Posted April 4, 2014 Share Posted April 4, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/287513-php-sign-up-form/#findComment-1474937 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.