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
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
Share on other sites

thank you, i dont know where i got isset from :?.

 

Thank you, I double posted because otherwise you may of thought it was fixed. an exit doesn't bring the topic to the top does it?

 

Anyway, thank you very much for that,

 

Snoobs :D

 

 

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.