Jump to content

Help with Signup Form (and process)


Catana

Recommended Posts

Hello,

 

Currently having issues with my sign up form. 

I feel I'm missing a bit of code for this form to work properly. 

 

Currently, I have a signup form that adds a new user into the site, this works fine and adds all the details to the database. 

The problem is, is that the button has to go through the signup_process php file, but currently it echos that the "new user has been created" on that file, but I need to use this file but echo that the "new user has been created" in the signup file (redirecting the user back to the signup page after clicking the button, but still goes through the signup_process file for processing)

 

Also, I need a way that will log the new user in, instantly after they have signed up so that don't have to login after successful sign up.

 

I'm also trying to validate my form so that details have to be entered in, I've started adding this, but doesn't seem to work right; it either does work and doesn't add a new user or it doesn't work and adds a new user.

 

I appreciate that the code I have may be old and does not contain proper security measures; but this is not at all important for the assignment I'm doing.

 

Thanks for any help.

 

PHP PROCESS FILE

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

<?php

	$username = $_POST['regusername'];
	$password = $_POST['regpassword'];
	$firstname = $_POST['regfirstname'];
	$surname = $_POST['regsurname'];
	$email = $_POST['regemail'];
	$dob = $_POST['regdob'];
	$gender = $_POST['reggender'];
	$city = $_POST['regcityname'];
	$sports = $_POST['regsports'];
	
	$query = "INSERT INTO `user`
	(user_username, user_password, user_firstname, user_surname, user_email, user_dob, user_gender, user_city)
	
	VALUES ('$username', '$password', '$firstname', '$surname', '$email', '$dob', '$gender', '$city')";
	
		$result = mysql_query($query);
			if($result) {
	
				echo "New user has been created!";
			} 		
			
?>

PHP SIGN UP FILE

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


<?php
	include "./includes/pagetop.php";
?>
<?php
	include "./includes/heading.php";
?>
<?php
	include "./includes/nav.php";
?>

<?php

// form validation
	
	$usernamevalid = $passwordvalid = "";
	$usernamefield = $passwordfield = "";
	
	if ($_SERVER["REQUEST_METHOD"] == "POST")
	
	{
		
		if (empty($_POST["regusername"]))
			{ $usernamevalid = "Username required!";}
		else
			{ $usernamefield = ($_POST["regusername"]);}
			
		if (empty($_POST["regpassword"]))
			{ $passwordvalid = "Password required!";}
		else
			{ $passwordfield = ($_POST["regpassword"]);}
		
	}
?>

<div id="content">

	<h3>Sign up</h3>
    
  		
      	<form name="input" action="signup_process.php" method="post">
        
        		<b>Login Details</b>
					<b>Username</b><input type="text" name="regusername">    <font color=red><?php echo $usernamevalid;?></font><br />
					<b>Password</b> <input type="password" name="regpassword">    <font color=red><?php echo $passwordvalid;?></font>
          </br>
            
          
        		<b>Personal Details</b>
					<b>First Name</b><input type="text" name="regfirstname"><br />
					<b>Surname</b> <input type="text" name="regsurname"><br />
                    <b>Email</b> <input type="text" name="regemail"><br /><br /> 
                   <b>Date of Birth</b> <input type="text" name="regdob"><br /><br />                           
                   <b>Gender</b> <input type="radio" name="reggender" value="1">Male 
                    	<input type="radio" name="reggender" value="2">Female <br /><br />
            		<b>City</b> <select id="cityname" name="regcityname">            
           				<?php 
							// city names
							foreach ($citynames as $key => $value){
								echo "<option value=\"$key\">$value</option>";				
							}			
						?>            
            		</select>                
</br>

        		<b>Sports</b>
                    	<?php
							// lists of sports
							$query = "SELECT sport_id, sport_name FROM sport";
							$result = mysql_query($query) or die (mysql_error());
							
							while($row = mysql_fetch_array($result)){
								$sports[$row['sport_id']] = $row['sport_name'];
							}
							
							foreach ($sports as $key => $value){
								
								echo "<div>\n";
								echo "<input type=\"checkbox\" id=\"$value\" name=\"sport[]\" value=\"$key\">\n";
								echo "<label for=\"$value\">$value</label>\n";
								echo "</div>\n";
								
							}					
						?>
					</select>			
            </br>
            
			<center><input type="submit" name="regsubmit" value="Sign up"></center><br />
    
	  	</form>
            
</div>
    
<?php
	include "./includes/adverts.php";
?>

<?php
	include "./includes/footer.php";
?>

<?php
	include "./includes/pagebottom.php";
?>
Link to comment
Share on other sites

Very annoying! For some reason if I enter incorrect details into the login form (located in page header) on the same page as the signup form, it then displays the validation errors on that signup form as well as the desired errors in the login form!?

Link to comment
Share on other sites

Not sure if I'm reading this properly given that its 4am lol.
 
However I'll try and shed a little light on this and hopefully can help you out somewhat.

From reading I understand you want it to echo the successful registration but also redirect onto another page? 

If so, have you tried using; 

$result = mysql_query($query);
           if($result){
echo '<script>alert("New user has been created!");</script>';
header("Location: xxxxx.php");
die("Redirecting to: xxxxx.php");
}
else
{
   print("Something went wrong with your registration.");
?>

As for logging a member in.after registering, try creating a session after the script succeeds.

 

  $result = mysql_query($query);
           if($result){
		   $_SESSION['loggedin'] = $result;
// echo
// redirect
?>

//Then on the top of the form you want them to be logged in with that session

<?php if(isset($_SESSION['loggedin'])){

//hi im logged in
}else{
// hi im not logged in
?> 

There might be a few mistakes here. But I hope it helps somewhat!

I'm PHP novice =)

Edited by alphamoment
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.