Jump to content

Form trouble, Not hard.


Snooble

Recommended Posts

I have 2 pages, register.php, checkregister.php. in register i thought i would (before each form textfield) place an if statement.

 

Which looks like this:

(I have the includes at the top of the page to start session...

			<?php if(isset($_SESSION['usernamereg'])){
		echo 'Please Eneter A Username:<input name="username" type="text" id="username" size="10" maxlength="10" value="'.$_SESSION['usernamereg'].'/>';
		} else {
		echo '<input name="username" type="text" id="username" size="10" maxlength="10"/>';
		}
		?>

 

On check register i have this:

 

<?php 
include 'expire.php';
include 'sessionstartandsql.php';
$_POST['username'] = $_SESSION['usernamereg'];
$_POST['password'] = $_SESSION['passwordreg'];
$_POST['email'] = $_SESSION['emailreg'];
if ($_POST['username'] == NULL){
	header("Location: register.php");}
if ($_POST['password'] == NULL){
	header("Location: register.php");}
if ($_POST['email'] == NULL){
        header("Location: register.php");}

$sql = "INSERT INTO wmusers VALUES ('".$_POST['username']."', '".$_POST['password']."', '".$_POST['email']."', '0', '0', '0')";
mysql_query($sql) or die ("Couldn't execute $sql: " . mysql_error()); 

?>

 

Any help? At the moment i get taken to the register page but i ALWAYS get the textfield without anything in it and without the "Please Eneter A Username:" bit echo'd.

 

There must be something wrong with the register page i think.

 

Snooble (Thanks in advance)

Link to comment
https://forums.phpfreaks.com/topic/41252-form-trouble-not-hard/
Share on other sites

I don't think session start is your problem...

 

Your logic is backwards.

 

<?php
...
$_POST['username'] = $_SESSION['usernamereg'];
$_POST['password'] = $_SESSION['passwordreg'];
$_POST['email'] = $_SESSION['emailreg'];

 

should be

 

<?php
$_SESSION['usernamereg'] = $_POST['username'];
$_SESSION['passwordreg'] = $_POST['password'];
$_SESSION['emailreg'] = $_POST['email'];

 

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

 

is always going to be true, no matter what. $_SESSION['usernamereg'] will be set, even if it's empty. Also, don't you want to display this only if it's empty?!? So you need to check if there's a value:

 

<?php if(strlen($_SESSION['usernamereg']) < 1) {

 

That will check to make sure it's empty.

 

I don't know if it will work, but try it and let us know what happens.

 

 

Link to comment
https://forums.phpfreaks.com/topic/41252-form-trouble-not-hard/#findComment-199864
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.