My registration is suddenly not working, any help appreciated

Hi,

Last night I was trying to add a re type password and captcha to my registration form and it seemed okay but when I tested it failed everytime, so then I removed both features and it still failed, now it just has the re type password as I figured it didn’t cause the issue.

The PHP from my registration form:


<?php
/**
 * Already logged in, cannot register
 */
if($session->logged_in){
   echo "<p>We're sorry <b>$session->username</b>, but you've already registered. "
       ."<a href=\\"index.php\\">Main</a>.</p>";
}
/**
 * The user has submitted the registration form and the
 * results have been processed.
 */
else if(isset($_SESSION['regsuccess'])){
   /* Registration was successful */
   if($_SESSION['regsuccess']){
      echo "<p>Thank you for registering <b>".$_SESSION['reguname']."</b>"
          .", you may now <a href=\\"index.php\\">log in</a>.</p>";
   }
   /* Registration failed */
   else{
      echo "<h1>Registration Failed</h1>";
      echo "<p>We're sorry, but an error has occurred and your registration for the username <b>".$_SESSION['reguname']."</b>, "
          ."could not be completed.<br>Please try again at a later time.</p>";
   }
   unset($_SESSION['regsuccess']);
   unset($_SESSION['reguname']);
}
else{
?>


<?
if($form->num_errors > 0){
   echo "<td><font size=\\"2\\" color=\\"#ff0000\\">".$form->num_errors." error(s) found</font></td>";
}
?>
<table><tr><td>
<form action="process.php" method="POST">
<table>
<tr>
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr><td>Username:</td><td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td><td><? echo $form->error("user"); ?></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass"); ?>"></td><td><? echo $form->error("pass"); ?></td></tr>
   <tr>
      <td>Retype Password:</td>
      <td><input type="password" name="pwdconfirm" maxlength="30"
                 value="<?php echo $form->value("pwdconfirm"); ?>"></td>
      <td><?php echo $form->error("pwdconfirm"); ?></td>
   </tr>
<tr><td>Email:</td><td><input type="text" name="email" maxlength="50" value="<? echo $form->value("email"); ?>"></td><td><? echo $form->error("email"); ?></td></tr>
<tr><td colspan="2" align="right">
<input type="hidden" name="subjoin" value="1">
<input type="submit" value="Join!"></td></tr>
</table>

</form>
</td></tr>
</table>

<?
}
?>

Only other thing in the doc is:


<?php
include("include/session.php");
?>

If anyone thinks it has to be in the sessions.php I’ll put the code up then.

Thanks in advance.

Would anyone trusted here be willing to check out my files themselves. I can give FTP access if needed or upload to somewhere of your choice.

Without knowing what your session.php actually does, it’s hard to say what might be breaking it’s logic flow… BUT…

Fixing your HTML and making it something MODERN certainly wouldn’t help with that tables for layout bloat… also it COULD be a method issue since it’s “post” not “POST” in any modern doctype, but that really shoudn’t matter. I’d probably also swing an axe at the stupid “opening and closing php every few lines” nonsense, the string additions and the use of double quotes on echo since it makes your code a confusing mess. (and potentially slower)

Uhm, on success you unset those $_SESSION values – could that be the problem? If it isset and the condition is true, those are running… are those supposed to be inside the ELSE?

Also you’re echoing a <td> outside the tables listed – is that right? Is this already inside a table? (If so just how deep is it nested for NOTHING?!?)

This probably doesn’t fix your problem, but at least makes the code clearer and drags it kicking and screaming into this decade instead of being stuck in the 90’s.


<?php 

if ($session->logged_in) {
	echo '
		<p>
			We're sorry <b>',$session->username,'</b>,
			but you've already registered. 
			<a href="index.php">Main</a>.
		</p>'; 
	
} else if (isset($_SESSION['regsuccess'])) { 

	if ($_SESSION['regsuccess']) { 
		echo '
		<p>
			Thank you for registering <b>',$_SESSION['reguname'],'</b>,
			you may now <a href="index.php">log in</a>.
		</p>'; 
			
	} else { // registration failed
		echo '
		<h1>Registration Failed</h1>
		<p>
			We\\'re sorry, but an error has occurred and your 
			registration for the username <b>',$_SESSION['reguname'],'</b>,
			could not be completed.<br />
			Please try again at a later time.
		</p>';
	} 
	
	unset($_SESSION['regsuccess']); 
	unset($_SESSION['reguname']); 
	
} else { 

	if ($form->num_errors>0) { 
		echo '
		<div class="error">
			',$form->num_errors,' error',(
				$form->num_errors==1 ? '' : 's'
			),'found
		</div>'; 
	} 
	
	echo '
		<form action="process.php" method="POST"> 
			<fieldset>
			
				<label for="processUser">Username:</label>
				<input
					type="text"
					name="user"
					id="processUser"
					maxlength="30"
					value="',$form->value('user'),'"
				/>
				<span>',$form->error('user'),'</span><br /> 
				
				<label for="processPassword">Password:</label>
				<input
					type="password"
					name="pass"
					id="processPassword"
					maxlength="30"
					value="',$form->value('pass'),'"
				/>
				<span>',$form->error('pass'),'</span><br />
				
				<label for="processPasswordConfirm">Retype Password:</label>
				<input
					type="password"
					name="pwdconfirm"
					id="processPasswordConfirm"
					maxlength="30" 
					value="',$form->value('pwdconfirm'),'"
				/>
				<span>',$form->error('pwdconfirm'),'></span><br />
				
				<label for="processEmail">Email:</label>
				<input
					type="text"
					name="email"
					id="processEmail"
					maxlength="50"
					value="',$form->value('email'),'"
				/>
				<span>',$form->error('email'),'</span><br />
				
				<input type="hidden" name="subjoin" value="1"> 
				<input type="submit" value="Join!"></td></tr> 
			</fieldset>
		</form>';
}
?>

probably a few typo’s in there, but you get the idea.

I appreciate the reply. I am rather new to PHP, in the past I have only done small edits ‘n’ such. I actually fixed the issue which may be because of my poor design of this. The problem was I added a website part to the user profile where you can set your own website but because it wasn’t in any way set in registration yet was in the user table where all the other information is stored it wouldn’t allow the registration to work until I had it send I guess, blank data to the column upon registration. I don’t really understand it but that’s what fixed it.

I will take what you said in and fix up some stuff.

You can see it all here: http://karoshio.net/test/index.php I didn’t know my code was so bad, it all works nicely to me.

With regard to the sessions problem, are you using session_start() in the session class, possibly in the constructor?

Sorry did I write something wrong, I’m having no session issues, but yes I am:


/* Class constructor */
   function Session(){
      $this->time = time();
      $this->startSession();
   }

   function startSession(){
      global $database; 
      session_start();   

session_start() needs to be declared before all other code but after the opening PHP tags <?php otherwise in your case the session won’t set because the rest of your code doesn’t actually know a session has been started.

Can someone explain why I am getting comments on the sessions. They have been working fine from the start.