Jump to content

Form Data not passing into Array


SalientAnimal

Recommended Posts

Hi All,

 

I am currently working on a login / registration page combination. My form seems to not be passing any of the data into the array to be written to the database. Could someone perhaps help me in identifying where this issue may be?

 

When clicking submit on registration, I get take to a blank page, and all the information entered in the form is displayed in the browser address bar (http://localhost/processing/register.php?usernamesignup=MyUsername&emailsignup=Mye-mail%40myemail.com&passwordsignup=123456&passwordsignup_confirm=123456) , adding var_dump($_POST);exit;  to my form submit page, the array is shown on a blank white page as array(0) { }

 

Please let me know if I show add my code, or if there are other error / validation checks I can do.

 

Thanks.

 

 

Link to comment
Share on other sites

In index.php file you have form tag without method, so by default form method is GET

 

just replace below line 

<form  action="mysuperscript.php" autocomplete="on">

with

<form  action="mysuperscript.php" autocomplete="on" method="post">

i hope this will work for you

Link to comment
Share on other sites

In index.php file you have form tag without method, so by default form method is GET

 

just replace below line 

<form  action="mysuperscript.php" autocomplete="on">

with

<form  action="mysuperscript.php" autocomplete="on" method="post">

i hope this will work for you

 

 

I can't believe I missed the method... Feel like a fool... Ok so now that I've added that I checked and can confirm that the array now holds the data, but now it's not writing to the database.

 

I still have to read through everything again so see what I may be missing.

Link to comment
Share on other sites

I can't believe I missed the method... Feel like a fool... Ok so now that I've added that I checked and can confirm that the array now holds the data, but now it's not writing to the database.

 

I still have to read through everything again so see what I may be missing.

 

also you have not given name to submit button

Link to comment
Share on other sites

you have not included "dbconfig.php" database connection file in "registration.php" file

also use error_reporting(E_ALL & ~E_NOTICE); at the top, to check PHP errors

 

Does the dbconfig.php file have to be on both the form page and the submit page?

 

Will include the error reporting now to check for additional info

Link to comment
Share on other sites

If you post some of your code here you might get more interest.  Some of us refuse to click on links to see code posted elsewhere.

Hi there,

 

I have included my code below. I uploaded the files here just in my earlier post.

 

 

Form Page:

<!DOCTYPE html>

<?php
//INCLUDE ANY INCLUDE FILES
error_reporting(E_ALL & ~E_NOTICE);
require_once('C:/xampp/htdocs/includes/dbconfig.php');


//CHECK IF THE USER IS ALREADY LOGGED IN
//IF THE USER IS LOGGED IN REDIRECT THEM TO THE HOMEPAGE
if( $user->is_logged_in() ){ header('Location: C:/xampp/htdocs/home.php'); } 


?>

<html>
	<head>
		<meta charset="utf-8">
		<!-- LINKING TO FAVICON FILES -->
		<!--[if IE]><link rel="shortcut icon" href=="img/favicon.ico"><![endif]-->
		<link rel="icon" href="img/favicon.png">
		<link rel="apple-touch-icon-precomposed" href="favicon.png">	

		
        <link rel="stylesheet" type="text/css" href="css/demo.css" />
        <link rel="stylesheet" type="text/css" href="css/style3.css" />
		<link rel="stylesheet" type="text/css" href="css/animate-custom.css" />		
	
	
	
		<!-- THIS IS THE TITLE TAG FOR THE CONTACT CENTRE MANAGEMENT SYSTEM -->
		<!-- <title><?php if(isset($title)){ echo $title; }?></title> -->
		<title>TechDesignLab - CCIS</title>
	</head>
		<body>
		
        <div class="container">

		    <!-- CODROPS TOP NAVIGATION BAR START -->
            <div class="codrops-top">
					<a href="">
						<strong>« Some Links</strong>Here
					</a>
                <span class="right">
                    <a href="http://www.techdesignlab.co.za">
                        <strong>System designed by TechDesignLab.co.za</strong>
                    </a>
                </span>
				
			<!-- TRANSPARENT HIGHLIGHT OVER TOP NAVIGATION -->
				<div class="clr"></div>

            </div>
			<!--/ CODROPS TOP NAVIGATION BAR END -->
		
		
            <header>
                <h1>YOUR COMPANY NAME / LOGO <span>Contact Centre Information Systems</span></h1>
            </header>

			
			<?php
			//CHECK PAGE FOR ANY ERRORS
			if(isset($error)){
				foreach($error as $error){
					echo '<p class="bg-danger">'.$error.'</p>';
				}
			}

			//IF THE ACTION IS JOINED SHOW SUCCESS
			if(isset($_GET['action']) && $_GET['action'] == 'joined'){
				echo "<h2 class='bg-success'>Registration successful, please check your email to activate your account.</h2>";
			}
			?>		

			
            <section>				
                <div id="container_demo" >
                    <!-- hidden anchor to stop jump http://www.css3create.com/Astuce-Empecher-le-scroll-avec-l-utilisation-de-target#wrap4  -->
                    <a class="hiddenanchor" id="toregister"></a>
                    <a class="hiddenanchor" id="tologin"></a>
                    <div id="wrapper">
                        <div id="login" class="animate form">
                            <form  action="processing/login.php" autocomplete="on" method="post"> 
                                <h1>Log in</h1> 
                                <p> 
                                    <label for="username" class="uname" data-icon="u" > Username / E-Mail </label>
                                    <input id="username" name="username" required="required" type="text" placeholder="YourUserName OR YourEmail@domain.com" value="" tabindex="1"/>
                                </p>
                                <p> 
                                    <label for="password" class="youpasswd" data-icon="p"> Password </label>
                                    <input id="password" name="password" required="required" type="password" placeholder="eg. X8df!90EO" tabindex="2"/>
                                </p>
                                <p class="keeplogin"> 
									<input type="checkbox" name="loginkeeping" id="loginkeeping" value="loginkeeping" tabindex="3"/>
									<label for="loginkeeping">Keep me logged in</label>
								</p>
                                <p class="login button"> 
                                    <input type="submit" value="Login" /> 
								</p>
                                <p class="change_link">
									Not registered yet ?
									<a href="#toregister" class="to_register">Register Here</a>
								</p>
                            </form>
                        </div>

						
						
                        <div id="register" class="animate form">
                            <form  action="processing/register.php" autocomplete="on" method="post"> 
                                <h1> Sign up </h1> 
                                <p> 
                                    <label for="usernamesignup" class="uname" data-icon="u">Username </label>
                                    <input id="usernamesignup" name="usernamesignup" required="required" type="text" placeholder="YourUserName" value="" tabindex="4"/>
                                </p>
                                <p> 
                                    <label for="emailsignup" class="youmail" data-icon="e" > E-Mail </label>
                                    <input id="emailsignup" name="emailsignup" required="required" type="email" placeholder="YourEmail@domain.com" value="" tabindex="5"/>
                                </p>
                                <p> 
                                    <label for="passwordsignup" class="youpasswd" data-icon="p"> Password </label>
                                    <input id="passwordsignup" name="passwordsignup" required="required" type="password" placeholder="eg. X8df!90EO" tabindex="6"/>
                                </p>
                                <p> 
                                    <label for="passwordsignup_confirm" class="youpasswd" data-icon="p">Password Confirmation </label>
                                    <input id="passwordsignup_confirm" name="passwordsignup_confirm" required="required" type="password" placeholder="eg. X8df!90EO" tabindex="7"/>
                                </p>
                                <p class="signin button"> 
									<input type="submit" value="Register" name="register"/> 
								</p>
                                <p class="change_link">  
									Already registered ?
									<a href="#tologin" class="to_register"> Login Here </a>
								</p>
                            </form>
                        </div>
						
                    </div>
                </div>  
  
            </section>
        </div>

		
		
		</body>





	<script>
	
	</script>
</html>

Submission Page:

<?php 
//IF THE FORM HAS BEEN SUBMITTED, PROCESS IT
error_reporting(E_ALL & ~E_NOTICE);
require_once('C:/xampp/htdocs/includes/dbconfig.php');





if(isset($_POST['submit'])){

	//VERY BASIC VALIDATION OF USERNAME
	if(strlen($_POST['usernamesignup']) < 6){
		$error[] = 'Your username is required to be a minimum of 6 characters.';
	} else {
		$stmt = $db->prepare('SELECT username FROM sys_members WHERE username = :username');
		$stmt->execute(array(':username' => $_POST['usernamesignup']));
		$row = $stmt->fetch(PDO::FETCH_ASSOC);

		if(!empty($row['usernamesignup'])){
			$error[] = 'The username you have entered is already in use.';
		}

	}

	if(strlen($_POST['passwordsignup']) < 6){
		$error[] = 'Your password should be at least 6 characters in length.';
	}

	if(strlen($_POST['passwordsignup_confirm']) < 6){
		$error[] = 'Your confirmation password should be at least 6 characters in length.';
	}

	if($_POST['passwordsignup'] != $_POST['passwordsignup_confirm']){
		$error[] = 'Passwords do not match.';
	}

	//VERY BASIC VALIDATION OF E-MAIL
	if(!filter_var($_POST['emailsignup'], FILTER_VALIDATE_EMAIL)){
	    $error[] = 'Please enter a valid email address';
	} else {
		$stmt = $db->prepare('SELECT email FROM sys_members WHERE email = :email');
		$stmt->execute(array(':email' => $_POST['emailsignup']));
		$row = $stmt->fetch(PDO::FETCH_ASSOC);

		if(!empty($row['emailsignup'])){
			$error[] = 'The e-maill address you have entered is already in use.';
		}

	}


	//IF NO ERRORS HAVE BEEN CREATED CARRY ON
	if(!isset($error)){

		//HASH THE PASSWORD
		$hashedpassword = $user->password_hash($_POST['passwordsignup'], PASSWORD_BCRYPT);

		//CREATE THE ACTIVATION CODE
		$activasion = md5(uniqid(rand(),true));

		try {

			//CREATE THE USER IN THE DATABASE USING A PREPARED STATEMENT
			$stmt = $db->prepare('INSERT INTO sys_members (username,email,password,active) VALUES (:username, :email, :password, :active)');
			$stmt->execute(array(
				':username' => $_POST['usernamesignup'],
				':email' => $_POST['emailsignup'],
				':password' => $hashedpassword,				
				':active' => $activasion
			));
			$id = $db->lastInsertId('memberID');

			//SEND A VERIFICATION / ACTIVATION E-MAIL TO THE USER
			$to = $_POST['emailsignup'];
			$subject = "Registration Confirmation";
			$body = "<p>Thank you for registering at demo site.</p>
			<p>To activate your account, please click on this link: <a href='".DIR."activate.php?x=$id&y=$activasion'>".DIR."activate.php?x=$id&y=$activasion</a></p>
			<p>Regards Site Admin</p>";

			$mail = new Mail();
			$mail->setFrom(SITEEMAIL);
			$mail->addAddress($to);
			$mail->subject($subject);
			$mail->body($body);
			$mail->send();

			//REDIRECT THE USER TO THE INDEX PAGE
			header('Location: .C:/xampp/htdocs/index.php?action=joined');
			exit;

		//ELSE CATCH THE EXCEPTION AND SHOW THE ERROR.
		} catch(PDOException $e) {
		    $error[] = $e->getMessage();
		}

	}

}

//DEFINE THE PAGE TITLE
$title = 'Demo';


?>
Link to comment
Share on other sites

Your form for registering the user has a submit button named register

<input type="submit" value="Register" name="register"/> 

But your code for registering the user will only run if POST value named submit exists

if(isset($_POST['submit'])){

You want to be checking if $_POST['register'] exists 

 

Why are you using filepaths in header redirects?

header('Location: C:/xampp/htdocs/home.php');
header('Location: .C:/xampp/htdocs/index.php?action=joined');

You should be using urls

header('Location: /home.php');
header('Location: /index.php?action=joined');

Also I wouldn't recommend hard coding absolute file paths. Instead either define a constant containing an absolute file path the root of your application (C:/xampp/htdocs) and prepend your file paths with that constant or use $_SERVER['DOCUMENT_ROOT'] instead

define('ROOT', 'C:/xampp/htdocs/');

require_once(ROOT . 'includes/dbconfig.php');

// OR use
require_once($_SERVER['DOCUMENT_ROOT'] . 'includes/dbconfig.php');

That way you only need to edit the file path in one place rather than having to hunt throughout your code to modify filepaths

Link to comment
Share on other sites

Thanks Ch0cu3r, I'm going to implement your recommendations now and will hopefully sort out my issues. I really appreciate the help here. I didn't really want to use the absolute files paths, but I wasn't / am not sure how to refer back to the correct files without either duplicating a dbconfig file as an example inside each folder, but this makes it tedious to update each time. I like to try and add "files" that perform different functions in different folders... But I'm not always entirely sure of how to do this.

 

From what you saying, is it safe to assume that I could always just have the $_SERVER['DOCUMENT_ROOT']. prefixed in front of any path / url and this will work? At the moment I am using file paths instead of url's because I'm doing a test build on my local machine.

Link to comment
Share on other sites

 

From what you saying, is it safe to assume that I could always just have the $_SERVER['DOCUMENT_ROOT']. prefixed in front of any path / url and this will work?

$_SERVER['DOCUMENT_ROOT'] is inherited form the http servers configuration. It will contain the absolute path to your sites root folder.

 

 

but I wasn't / am not sure how to refer back to the correct files without either duplicating a dbconfig file as an example inside each folder

 

If you are using absolute files paths there should not be an issue for knowing what path to use to include any file in your application. File paths can become a lot more tricky when you start using relative paths.

Link to comment
Share on other sites

$_SERVER['DOCUMENT_ROOT'] is inherited form the http servers configuration. It will contain the absolute path to your sites root folder.

 

 

If you are using absolute files paths there should not be an issue for knowing what path to use to include any file in your application. File paths can become a lot more tricky when you start using relative paths.

 

Thanks again for your help, I have gone with the $_SERVER['DOCUMENT_ROOT'] option, and now have my form processing correctly and generating an activation e-mail with the link as expected (all data written to database). Now I just need to figure out as to why the activation e-mail delivery is failing / being rejected. A slow process to building this, but so far I am liking what I am seeing. 

Link to comment
Share on other sites

If you are using PHP's mail function then you need configure the mail settings in the php.ini

 

As you are using XAMPP locally you may find this helpful

 

I am using / attempting to use PHP's mail function.

 

How would I get access to the pgp.ini file though if I'm having my files run by a hosting company? Wouldn't / shouldn't these setting then already have been applied?

Link to comment
Share on other sites

 

How would I get access to the pgp.ini file though if I'm having my files run by a hosting company? Wouldn't / shouldn't these setting then already have been applied?

You wouldn't need to do that, your webhost will have everything setup for you. Unless you have dedicated hosting.

Link to comment
Share on other sites

You wouldn't need to do that, your webhost will have everything setup for you. Unless you have dedicated hosting.

 

I thought they would have it setup because I can't access or see any of the config files. So what could be missing / preventing the e-mails from coming through?

 

Is there a check I can run?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.