This topic is locked
[SOLVED]

 New User Registration

1/6/2006 6:24:06 PM
PHPRunner General questions
A
Alan4573 author

Sorry, it's me again,
I get a blank page when I click on "Register" on login.php
The code for register.php generated is as follows:
<?php

ini_set("display_errors","1");

ini_set("display_startup_errors","1");

session_start();

set_magic_quotes_runtime(0);

session_unset();
include("include/dbcommon.php");

include("include/dbconnection.php");
$cEmailField = "email";
$registered=false;

$onload=' ';

$strMessage="";

$strUsername="";

$strPassword="";

$strEmail="";
if(@$_POST["btnSubmit"] == "Register")

{

$conn=db_connect();

$rstemp=db_query("select from ".AddTableWrappers($cLoginTable)." where 1=0",$conn);
$fields="";

$values="";

$ind=1;

$userdata = array()
$userinfo[$ind] = refine(@$_POST["userinfo".$ind]);

$userdata["username"]=$userinfo[$ind];

if(NeedQuotes(db_fieldtype($rstemp,"username")))

$dbval="'".db_addslashes($userinfo[$ind])."'";

else

$dbval=(0+$userinfo[$ind]);
if(strlen($fields))

{

$fields.=",".AddFieldWrappers("username");

$values.=",".$dbval;

}

else

{

$fields.=AddFieldWrappers("username");

$values.=$dbval;

}

if("username"==$cUserNameField)

{

$strUsername = $userinfo[$ind];

$dbstrUsername = $dbval;

}

if("username"==$cEmailField)

{

$strEmail = $userinfo[$ind];

$dbstrEmail = $dbval;

}

if("username"==$cPasswordField)

$strPassword = $userinfo[$ind];

$ind++;
$userinfo[$ind] = refine(@$_POST["userinfo".$ind]);

$userdata["password"]=$userinfo[$ind];

if(NeedQuotes(db_fieldtype($rstemp,"password")))

$dbval="'".db_addslashes($userinfo[$ind])."'";

else

$dbval=(0+$userinfo[$ind]);
if(strlen($fields))

{

$fields.=",".AddFieldWrappers("password");

$values.=",".$dbval;

}

else

{

$fields.=AddFieldWrappers("password");

$values.=$dbval;

}

if("password"==$cUserNameField)

{

$strUsername = $userinfo[$ind];

$dbstrUsername = $dbval;

}

if("password"==$cEmailField)

{

$strEmail = $userinfo[$ind];

$dbstrEmail = $dbval;

}

if("password"==$cPasswordField)

$strPassword = $userinfo[$ind];

$ind++;
$userinfo[$ind] = refine(@$_POST["userinfo".$ind]);

$userdata["email"]=$userinfo[$ind];

if(NeedQuotes(db_fieldtype($rstemp,"email")))

$dbval="'".db_addslashes($userinfo[$ind])."'";

else

$dbval=(0+$userinfo[$ind]);
if(strlen($fields))

{

$fields.=",".AddFieldWrappers("email");

$values.=",".$dbval;

}

else

{

$fields.=AddFieldWrappers("email");

$values.=$dbval;

}

if("email"==$cUserNameField)

{

$strUsername = $userinfo[$ind];

$dbstrUsername = $dbval;

}

if("email"==$cEmailField)

{

$strEmail = $userinfo[$ind];

$dbstrEmail = $dbval;

}

if("email"==$cPasswordField)

$strPassword = $userinfo[$ind];

$ind++;
$retval=true;

if(function_exists("BeforeRegister"))

$retval = BeforeRegister($userdata);
$strMessage="";

// check if entered username already exists

if(!strlen($strUsername))

$strMessage="Username can not be empty.";

else

{

$strSQL="select count(
) from ".AddTableWrappers($cLoginTable)." where ".AddFieldWrappers($cUserNameField)."=".$dbstrUsername;

$rs=db_query($strSQL,$conn);

$data=db_fetch_numarray($rs);

if($data[0]>0)

$strMessage="Username"." <i>".$strUsername."</i> "."already exists. Choose another username.";

}
// check if entered email already exists
if(!strlen($strEmail))

$strMessage="Please enter valid email address.";

else

{

$strSQL="select count(*) from ".AddTableWrappers($cLoginTable)." where ".AddFieldWrappers($cEmailField)."=".$dbstrEmail;

$rs=db_query($strSQL,$conn);

$data=db_fetch_numarray($rs);

if($data[0]>0)

{

if($strMessage)

$strMessage.="
";

$strMessage.="Email"." <i>".$strEmail."</i> "."already registered. If you forgot your username or password use the password reminder form.";

}

}
if(!$strMessage && $retval)

{

$strSQL="insert into ".AddTableWrappers($cLoginTable)." (".$fields.") values (".$values.")";

db_exec($strSQL,$conn);
if(function_exists("AfterSuccessfulRegistration"))

AfterSuccessfulRegistration();
// send email to user

$message="You have registered as user at http://".$_SERVER["SERVER_NAME"].$_SERVER["SCRIPT_NAME"]."\r\n"'>http://".$_SERVER["SERVER_NAME"].$_SERVER["SCRIPT_NAME"]."\r\n";;

$ind=1;
$label = "Username";

$message.=$label.": ".$userinfo[$ind++]."\r\n";
$label = "Password";

$message.=$label.": ".$userinfo[$ind++]."\r\n";
$label = "Email";

$message.=$label.": ".$userinfo[$ind++]."\r\n";
mail($strEmail,"Notification on registering",$message);
// send letter to admin

$message="User registered at http://".$_SERVER["SERVER_NAME"].$_SERVER["SCRIPT_NAME"]."\r\n"'>http://".$_SERVER["SERVER_NAME"].$_SERVER["SCRIPT_NAME"]."\r\n";;

$ind=1;
$label = "Username";

$message.=$label.": ".$userinfo[$ind++]."\r\n";
$label = "Password";

$message.=$label.": ".$userinfo[$ind++]."\r\n";
$label = "Email";

$message.=$label.": ".$userinfo[$ind++]."\r\n";
mail("alan@aws-services.com","Notification on registering",$message);
$registered=true;

$onload="";

}

else

if(function_exists("AfterUnsuccessfulRegistration"))

AfterUnsuccessfulRegistration();
}
if(function_exists("RegisterOnLoad"))

RegisterOnLoad();
?>
<html>

<head>

<title>Register</title>

<link REL="stylesheet" href="include/style.css" type="text/css">

</head>

<script language = JavaScript>
function OnKeyDown()

{

e = window.event;

if (e.keyCode == 13)

{

e.cancel = true;

document.forms[0].submit();

}

}

</script>

<body bgcolor=white <?php echo $onload;?> text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" link="#0066cc">

<?php

if(file_exists("include/supertop.php"))

include("include/supertop.php");

?>

<table width="100%" border="0" cellspacing="0" cellpadding="0" height="99%">

<tr>

<td valign="center" align="middle">

<table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr>

<td>&nbsp;</td>

</tr>

</table>

<table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr>

<td>

<table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr>

<td bgcolor="#ffffff" valign="top" align="right">

<table width="300" border="0" cellspacing="4" cellpadding="4" align="center">

<tr>

<td>&nbsp;</td>

</tr>

</table>

<table width="300" border="0" cellspacing="1" cellpadding="4" align="center" bgcolor="#cccccc">

<tr>

<td align=middle class=blackshade>

<b><font size=+1>Register</font></b></td>

</tr>

<tr>

<td valign="top" class=shade>

<DIV align=center>

<table width="200" border=0 align="center" class=shade>

<tbody>

<tr height=10><td colspan=2>&nbsp;</td></tr>

<?php if(!$registered) {?>

<form method="POST" action="register.php" id=form1 name=form1>

<?php $ind=1;?>
<!--username-->

<tr>
<td align=right width="50%">

<div align="left"><?php echo "Username"; ?>:</div>

</td>

<td width="50%">

<input type=text name="userinfo<?php echo $ind;?>" value="<?php if(isset($userinfo[$ind])) echo htmlspecialchars($userinfo[$ind]);?>" >

</td>
<?php $ind++; ?>

</tr>
<!--password-->

<tr>
<td align=right width="50%">

<div align="left">Password:</div>

</td>

<td width="50%">

<input type=password id="password" name=userinfo<?php echo $ind;?> value="<?php if(isset($userinfo[$ind])) echo htmlspecialchars($userinfo[$ind]);?>">

</td>

</tr>

<tr>

<td align=right width="50%">

<div align="left">Re-enter password:</div>

</td>

<td width="50%">

<input type=password id="password1" name=password1 value="<?php if(isset($userinfo[$ind])) echo htmlspecialchars($userinfo[$ind]);?>">

</td>
<?php $ind++; ?>

</tr>
<!--email-->

<tr>
<td align=right width="50%">

<div align="left"><?php echo "Email"; ?>:</div>

</td>

<td width="50%">

<input type=text name="userinfo<?php echo $ind;?>" value="<?php if(isset($userinfo[$ind])) echo htmlspecialchars($userinfo[$ind]);?>" >

</td>
<?php $ind++; ?>

</tr>
<tr>

<td colspan=2 align=middle>

<input type=hidden name=btnSubmit value="Register">

<input type=submit value="Submit" class=buttonM onclick="java script: if(document.getElementById('password').value!=document.getElementById('password1').value) {alert('Passwords do not match. Re-enter password');document.getElementById('password1').value='';return false;} return true;">

</td>

</tr>

<tr>

<td colspan=2 align=middle>

<a href="login.php">Back to login page</a>

</td>

</tr>

<tr height=20>

<td align=center colspan=2>

<font color=red><?php echo $strMessage;?></font>&nbsp;

</td></tr>

<?php } else {?>

<form method="POST" action="login.php" id=form1 name=form1>

<input type="Hidden" name=username value="<?php echo htmlspecialchars($strUsername);?>">

<input type="Hidden" name=password value="<?php echo htmlspecialchars($strPassword);?>">

<tr>

<td colspan=2 align=middle>

Registration successful!
<a href="login.php" onclick="form1.submit(); return false;">Proceed to login page</a>

</td>

</tr>

<?php } ?>

</tbody>

</table></DIV>

</td>

</tr>

</table>

</form>

<p>&nbsp;</p></td>

</tr>

</table>
</td>

</tr>

</table>

</td>

</tr>

</table>

<?php

if(file_exists("include/superbottom.php"))

include("include/superbottom.php");

?>

</body>

</html>

<?php

// refine value passed by POST or GET method

function refine($str)

{

$ret=$str;

if(get_magic_quotes_gpc())

$ret=stripslashes($str);

return html_special_decode($ret);

}
function html_special_decode($str)

{

$ret=$str;

$ret=str_replace("&gt;",">",$ret);

$ret=str_replace("&lt;","<",$ret);

$ret=str_replace("&quot;","\"",$ret);

$ret=str_replace("'","'",$ret);

$ret=str_replace("&amp;","&",$ret);

return $ret;

}

?>
Anybody got any ideas?

A
Alan4573 author 1/6/2006

Sergey,
This is definitely a bug in version 3.0 Beta <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=7387&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' />
How do I know?
Well, first I uninstalled version 3.0 then reinstalled it. Same thing - blank register.php page <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=7387&image=2&table=forumreplies' class='bbc_emoticon' alt=':(' />
Next I uninstalled version 3.0 again and reverted to version 2.0. Everything ok, register page now showing and working <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=7387&image=3&table=forumreplies' class='bbc_emoticon' alt=':D' />
Just to double check, I then saved a copy of the file source/register.php (version 2.0)
I then uninstalled version 2.0 and reinstalled version 3.0 - fault reappears, i.e register.php is blank <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=7387&image=4&table=forumreplies' class='bbc_emoticon' alt=':(' />
I then replaced the version 3.0 source/register.php file with the version 2.0 source/register.php file I saved earlier and tried again - BINGO <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=7387&image=5&table=forumreplies' class='bbc_emoticon' alt=':D' /> , the register.php page is now showing and it works. (It registers users and updates the database anyway - I haven't yet tried sending emails to user and admin)
This obviously can't be a permanent fix as the version 3.0 register.php file has 296 lines of code whereas the version 2.0 register.php file has only got 274 lines of code - obviously there's one or two additions to the newer version. I presume the error lies in that additional code somewhere. It's late however and I haven't the time to look at it just now.

At least I have it partially working now <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=7387&image=6&table=forumreplies' class='bbc_emoticon' alt=':P' />
I also wanted to try and have the events check if the username exists during registration and if so, requesting another, but I've still not got the hang of setting up the events and actions..... <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=7387&image=7&table=forumreplies' class='bbc_emoticon' alt=':(' />
Regards
Alan