POST Form not Working

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 1226 Views - Last Post: 26 January 2016 - 11:58 AM Rate Topic: -----

#1 DibDibs   User is offline

  • New D.I.C Head

Reputation: -14
  • View blog
  • Posts: 42
  • Joined: 13-December 15

POST Form not Working

Posted 24 January 2016 - 01:39 PM

Hi, I have been experiencing some problems with my POST form in HTML recently, can anyone guide me as to why it is not working.

This is the area of code that I think is messed up:-
<form method="POST" name="reg">
			Username*
			<input name="user" class="field" placeholder="Username" type="text" /><div class="note">Usernames must be between 4 - 27 characters long.</div>
			<div class="err"><?php if ($_GET['err_user'] == true) echo("That username cannot be used.");
			if ($_GET['taken_user'] == true) echo("That username has been taken.");
			?></div>
			<br><br>
			
			Password*
			<input name="pass" type="password" class="field" placeholder="Password" /><div class="note">Passwords must contain at least one number and a capital letter. They also must be over 6 characters long.</div>
			<div class="err"><?php if ($_GET['err_pass'] == true) echo("That password it too weak.");
			?></div>
			<br><br>
			
			Password Confirmation*
			<input name="passconf" type="password" class="field" placeholder="Password Confirmation" />
			<div class="err"><?php if ($_GET['err_pass_mismatch'] == true) echo("These passwords do not match.");
			?></div>
			<br><br>
			
			Forename*
			<input name="fname" type="text" class="field" placeholder="First Name" />
			<br><br><br>
			
			Surname
			<input name="sname" type="text" class="field" placeholder="Second Name" /><div class="note">You may include other names here too.</div>
			<br><br>
			
			E-Mail Address*
			<input name="email" type="text" class="field" placeholder="E-Mail Address" /><div class="note">You will be prompted for confirmation via this e-mail.</div>
			<br><br>
			
			Date of Birth*
			<input name="dob" type="date" class="field" />
			<div class="err"><?php if ($_GET['err_date_young'] == true) echo("You must be, at least, 12 years old to use Quizazle."); ?></div>
			<br><br>
			
			I agree to Quizazle's <a href="/terms" class="txt">Terms and Conditions</a>, and<br>I understand that a breach of said terms will result in account suspension or termination.
			<input name="terms" type="checkbox" class="css-checkbox" style="position:absolute; transform:translateY(-17.5px)" value="1" />
			<div class="err"><?php if ($_GET['err_agree_terms'] == true) echo("You must agree to our Terms and Conditions."); ?></div><br><br>
			
			I acknowledge that I am either over the age of 18, or under the age of 18 and have<br>my parents' permission to use Quizazle.<br>I also acknowledge that Quizazle cannot be held responsible for any mature content you see on our site.
			<input name="age" type="checkbox" class="css-checkbox" style="position:absolute; transform:translateY(-23px)" value="1" />
			<div class="err"><?php if ($_GET['err_agree_age'] == true) echo("You must agree to our Terms and Conditions."); ?><br><br>
			
			<input name="sub" type="submit" class="btn-s" value="Register" />
		</form>


And this is my full code:-
<!DOCTYPE html>
<html lang="en">

<?php
session_start();
error_reporting(E_ALL);
include "scripts/include.php";
$con = sql_open();

?>

<head>

<title>Register</title>
<link rel="stylesheet" media="screen" href="styles/main.php" />

</head>

<body>
<br>
<?php echo('<div align="center" style="position:fixed">' . head("Register") . '</div>'); ?><br><br>
<?php echo(ad_banner());?>
<br><br>

<br><br>
<table width="85%" id="menu" border="0" align="center" cellpadding="1" cellspacing="1">
  <tr>
    <td><div class="txt">Hello and Welcome to Quizazle. Thank you for taking an interest in our site.<br>Please, fill in all fields marked with an asterisk (*), fields without ans asterix are optional.<br>If you already have an account, please <a href="/login" class="txt" style="font-size:17.5px">click here</a> to login.<br><br>
		
		<form method="POST" name="reg">
			Username*
			<input name="user" class="field" placeholder="Username" type="text" /><div class="note">Usernames must be between 4 - 27 characters long.</div>
			<div class="err"><?php if ($_GET['err_user'] == true) echo("That username cannot be used.");
			if ($_GET['taken_user'] == true) echo("That username has been taken.");
			?></div>
			<br><br>
			
			Password*
			<input name="pass" type="password" class="field" placeholder="Password" /><div class="note">Passwords must contain at least one number and a capital letter. They also must be over 6 characters long.</div>
			<div class="err"><?php if ($_GET['err_pass'] == true) echo("That password it too weak.");
			?></div>
			<br><br>
			
			Password Confirmation*
			<input name="passconf" type="password" class="field" placeholder="Password Confirmation" />
			<div class="err"><?php if ($_GET['err_pass_mismatch'] == true) echo("These passwords do not match.");
			?></div>
			<br><br>
			
			Forename*
			<input name="fname" type="text" class="field" placeholder="First Name" />
			<br><br><br>
			
			Surname
			<input name="sname" type="text" class="field" placeholder="Second Name" /><div class="note">You may include other names here too.</div>
			<br><br>
			
			E-Mail Address*
			<input name="email" type="text" class="field" placeholder="E-Mail Address" /><div class="note">You will be prompted for confirmation via this e-mail.</div>
			<br><br>
			
			Date of Birth*
			<input name="dob" type="date" class="field" />
			<div class="err"><?php if ($_GET['err_date_young'] == true) echo("You must be, at least, 12 years old to use Quizazle."); ?></div>
			<br><br>
			
			I agree to Quizazle's <a href="/terms" class="txt">Terms and Conditions</a>, and<br>I understand that a breach of said terms will result in account suspension or termination.
			<input name="terms" type="checkbox" class="css-checkbox" style="position:absolute; transform:translateY(-17.5px)" value="1" />
			<div class="err"><?php if ($_GET['err_agree_terms'] == true) echo("You must agree to our Terms and Conditions."); ?></div><br><br>
			
			I acknowledge that I am either over the age of 18, or under the age of 18 and have<br>my parents' permission to use Quizazle.<br>I also acknowledge that Quizazle cannot be held responsible for any mature content you see on our site.
			<input name="age" type="checkbox" class="css-checkbox" style="position:absolute; transform:translateY(-23px)" value="1" />
			<div class="err"><?php if ($_GET['err_agree_age'] == true) echo("You must agree to our Terms and Conditions."); ?><br><br>
			
			<input name="sub" type="submit" class="btn-s" value="Register" />
		</form>
		</div></td>
  </tr>
</table>

<?php

if ($_POST['sub'] == "Register"){
	//Prepare Strings
	$user = $_POST['user']; //Prepare later, requires analysis
	$passwd = $_POST['passwd']; //Prepare later, requires analysis
	$passwdconf = $_POST['passconf']; //Prepare later, requires analysis
	
	$fname = sql_prep($_POST['fname']);
	$sname = sql_prep($_POST['sname']);
	$email = sql_prep($_POST['email']);
	
	$dob = date_create($_POST['dob']); //Create date from DOB.
	
	$err = [];
	echo(($_POST['user']));
	//Check Username
	if (strlen($user) < 4 && strlen($user) > 27) array_push($err, "err_user");;
	
	$prepusr = sql_prep($user);
	$inf = mysqli_query("SELECT * FROM `accounts` WHERE `username`='$prepusr'");
	if ($inf != 0) array_push($err, "taken_user");
	$user = $prepusr;
	
	//Check Password
	if ($passwd != $passwdconf) array_push($err, "err_pass_mismatch");
	if (!preg_match('/[A-Z]+[a-z]+[0-9]+/', $passwd)) array_push($err, "err_pass");
	$passwd = sql_prep(pwd_encrypt($passwd));
	
	//Calculate Age
	$birth = explode($dob, "-");
	$age = date_diff($dob, date_create('today'))->y;
	
	if ($age < 12) array_push($err, "err_date_young");
	$dob = sql_prep($dob);
	
	//Check User has Agreed to both Checkboxes
	if ($_POST['terms'] != "1") array_push($err, "err_agree_terms");
	
	if ($_POST['age'] != "1") array_push($err, "err_agree_age");
	
	
	if (count($err) == 0){ //CREATE ACCOUNT
		$today = sql_prep(date("Y-m-d"));
		$confirm = uniqid("VERIF", true);
		$uid = uniqid("", true);
		
		mysqli_query($con, "INSERT INTO `accounts`
		(`longid`, `username`, `password`, `email`, `fname`, `sname`, `dob`, `points`, `lev`, `conf`, `created`)
		VELUES ('$uid', '$user', '$passwd', '$email', '$fname', '$sname', '$dob', '0', '0', '$confirm', '$today')");
		
		echo('<META HTTP-EQUIV="Refresh" Content="0; URL=/regsuccess">');
	}
	
	else{
		if (count($err) == 1){
			echo('<META HTTP-EQUIV="Refresh" Content="0; URL=/register?$err[0]=true">');
		}
		
		else{
			$url = "";
			$c = 0;
			foreach ($err as $val){
				if ($c == 1){
					$url = $val . "=true";
				}
				else{
					$url = $url . "&" . $val . "=true";
				}
				$c = $c + 1;
			}
			
			echo("<META HTTP-EQUIV='Refresh' Content='0; URL=/register?$url'>");
		}
	}
}

?>

<?php echo('<br><br><div align="center" style="position:fixed">' . foot() . '</div>'); ?>

</body>
<?php sql_close($con); ?>
</html>


I have tried rearranging the form, putting POST in lower and upper case for the method, adding and removing '/' from the end of my input tags, chanhing the names of inputs and echoing results, but all has failed and no results are echoed, leading me to beleive that the form is broken. Thanks in advance for any help :)

Is This A Good Question/Topic? 0
  • +

Replies To: POST Form not Working

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14349
  • View blog
  • Posts: 57,541
  • Joined: 12-June 08

Re: POST Form not Working

Posted 24 January 2016 - 01:47 PM

Please explain more on what isn't working.
Was This Post Helpful? 0
  • +
  • -

#3 DibDibs   User is offline

  • New D.I.C Head

Reputation: -14
  • View blog
  • Posts: 42
  • Joined: 13-December 15

Re: POST Form not Working

Posted 24 January 2016 - 02:05 PM

Basically, when data is submitted through the form, the PHP code below cannot handle and echo the data given via the form.

For example, if I give a username and try to echo it out below, it will not return a result.

So, basically, no information is being stored and collected by the form.
Does that help, if not, please say :)
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is online

  • Unprocessable Entity
  • member icon

Reputation: 6594
  • View blog
  • Posts: 26,830
  • Joined: 12-December 12

Re: POST Form not Working

Posted 24 January 2016 - 02:32 PM

One issue is that the input is named pass not passwd. You've also misspelt VALUES.

Add this at the top of your code to display all errors:
error_reporting(E_ALL);
ini_set('display_errors', '1');

You should also read this tutorial, Progressive Testing.
Was This Post Helpful? 1
  • +
  • -

#5 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2652
  • View blog
  • Posts: 10,581
  • Joined: 03-December 12

Re: POST Form not Working

Posted 24 January 2016 - 02:50 PM

Skimming the code, there is a logic error and extra character on line 98 and a typo on line 130.

It would behoove you to separate some of that code out. It is quite difficult to follow as is.

Prepared Statements would also help you a great deal.
Was This Post Helpful? 1
  • +
  • -

#6 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2652
  • View blog
  • Posts: 10,581
  • Joined: 03-December 12

Re: POST Form not Working

Posted 24 January 2016 - 03:34 PM

This is not an HTML issue. Moving to PHP.
Was This Post Helpful? 1
  • +
  • -

#7 DibDibs   User is offline

  • New D.I.C Head

Reputation: -14
  • View blog
  • Posts: 42
  • Joined: 13-December 15

Re: POST Form not Working

Posted 25 January 2016 - 09:07 AM

OK, thanks for the suggestions, I'll take a loom and correct the errors you have given and I'll get back to you :D
Was This Post Helpful? 0
  • +
  • -

#8 no2pencil   User is online

  • Professor Snuggly Pants
  • member icon

Reputation: 6696
  • View blog
  • Posts: 31,047
  • Joined: 10-May 07

Re: POST Form not Working

Posted 25 January 2016 - 10:27 AM

First thing to do when testing POST values from a form, print_r($_POST);
Was This Post Helpful? 1
  • +
  • -

#9 DibDibs   User is offline

  • New D.I.C Head

Reputation: -14
  • View blog
  • Posts: 42
  • Joined: 13-December 15

Re: POST Form not Working

Posted 25 January 2016 - 11:25 AM

okay, so I have corrected my errors and added the code to display errors. I get no errors reflecting why it is not reading data, so, there are no errors when I try to echo something out from the form.

If you want to see the errors, go here. Just put some random info in, it won't make the account yet...
Was This Post Helpful? 0
  • +
  • -

#10 DibDibs   User is offline

  • New D.I.C Head

Reputation: -14
  • View blog
  • Posts: 42
  • Joined: 13-December 15

Re: POST Form not Working

Posted 25 January 2016 - 02:46 PM

does anyone have any ideas?
Was This Post Helpful? -2
  • +
  • -

#11 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14349
  • View blog
  • Posts: 57,541
  • Joined: 12-June 08

Re: POST Form not Working

Posted 25 January 2016 - 02:55 PM

Please remember this is a volunteer forum, and not to excessively bump you thread.
Was This Post Helpful? 1
  • +
  • -

#12 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2091
  • View blog
  • Posts: 6,398
  • Joined: 15-January 14

Re: POST Form not Working

Posted 25 January 2016 - 04:02 PM

The errors on the page when you load the form are because you're trying to access things in $_POST that aren't there, that's what undefined index means. You can use isset to check if it is set before trying to access it.

http://php.net/manua...ction.isset.php
Was This Post Helpful? 0
  • +
  • -

#13 DibDibs   User is offline

  • New D.I.C Head

Reputation: -14
  • View blog
  • Posts: 42
  • Joined: 13-December 15

Re: POST Form not Working

Posted 26 January 2016 - 10:25 AM

Thanks for the help Artificial, I already knew this though, and I don't think it has anything to do with the initial problem, but I'll give it a shot...

And modi123_1, 3 hours, is that 'excessive'?
Excessive (adjective); going beyond the usual, necessary, or proper limit or degree; characterized by excess.

This post has been edited by DibDibs: 26 January 2016 - 10:25 AM

Was This Post Helpful? 0
  • +
  • -

#14 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14349
  • View blog
  • Posts: 57,541
  • Joined: 12-June 08

Re: POST Form not Working

Posted 26 January 2016 - 10:27 AM

Yes.. that is excessive for this forum. Your post was still on the top few of the subforum thread and only three hours earlier. Typically I would expect eight or so hours would be more appropriate.

Let's not abuse the rep system because you disagree with me. That's how folks end up not having access to the rep system at all.
Was This Post Helpful? 0
  • +
  • -

#15 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2091
  • View blog
  • Posts: 6,398
  • Joined: 15-January 14

Re: POST Form not Working

Posted 26 January 2016 - 10:55 AM

What code are you using now? Are you still using a meta tag to redirect the browser? If so, then you're not going to see anything that PHP prints anyway. If your goal is just to test to make sure that PHP is getting the form data then remove the redirects while you're testing.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2