after a previous post, I reduced a script so that I could find the errors. This I did.. and I made significant gains in the process :¬)
But now I'm stuck!
When the simple form is filled in, the page just losed the info typed in and has
"already used. Select another member ID." at the top of the page.
I can see that it should have the visitors new ID written before it... but can't find the error in the script!
Here's the form:
<html>
<?php
/* File: login_form_test.php
* Desc: Displays login page. Page displays one form to provide
the information needed to apply for a new account.
*/ // 7
?>
<!-- form for new member to fill in -->
<form action="login_test.php?do=new" method="post">
<input type="hidden" name="do" value="new">
<p>
<table border="0" width="100%">
<?php
if (isset($message_new)) // 48
echo "<tr><td colspan='2'><b>$message_new</b></td></tr>";
?>
<tr>
<td align="right"><b>Member ID</b></td>
<td><input type="text" name="newname"
value="<?php echo $newname ?>"
size="20" maxlength="20"></td>
</tr>
<tr>
<td align="right"><b>Password</b></td>
<td><input type="password" name="newpass"
value="<?php echo $newpass ?>"
size="10" maxlength="8"></td>
</tr>
<tr>
<td align="right"><b>First Name</b></td>
<td><input type="text" name="firstname"
value="<?php echo $firstname ?>"
size="40" maxlength="40"></td>
</tr>
<tr>
<td align="right"><b>Last Name</b></td>
<td><input type="text" name="lastname"
value="<?php echo $lastname ?>"
size="40" maxlength="40"></td>
</tr>
<tr>
<td align=right><b>Email Address</b></td>
<td><input type="test" name="email" value="<?php echo $email ?>"
size="55" maxlength="67"></td>
</tr>
<tr>
<td> </td>
<td align="center"> <input type="submit" value="Become a Member"></td>
</tr>
</table>
</form>
</td>
</tr>
<tr><td colspan="3" bgcolor="gray"> </td></tr>
</table>
</body>
</html>
............ and the php script to accompany it...
<?php
/* Program: Login.php
Desc: Login program for the Members Only section of the
site. Enter a new login name. Login
Names, passwords and details are stored in a MySQL database.
*/
session_start(); // 8
session_register('auth'); // 9
session_register('logname');
include("access.php"
; // 11
switch (@$do) // 12
{
case "new": // 60
foreach($HTTP_POST_VARS as $key => $value) // 61
if (ereg("{Name)",$key)) // 74
{
if (!ereg("^[A-Za-z' -]{1,50}$",$key))
{
unset($do);
$message_new = "$lastname is not a valid name.
Please try again.";
include("login_form_test.php"
;
exit();
}
}
$$key = strip_tags(trim($value)); // 85
}
/* check to see if login name already exists */
$connection = mysql_connect($host,$user,$password) // 123
or die ("Couldn't connect to server."
;
$db = mysql_select_db($database, $connection)
or die ("Couldn't select database."
;
$sql = "SELECT member_ID FROM nmc_site_members
WHERE member_ID='$newname'";
$result = mysql_query($sql)
or die("Couldn't execute query."
;
$num = mysql_num_rows($result);
if ($num > 0) // 132
{
unset($do);
$message_new = "$newname already used. Select another
member ID.";
include("login_form_test.php"
;
exit();
}
else // 140
{
$today = time("Y-m-d"
;
$sql = "INSERT INTO nmc_site_members (member_ID,createdate,password,
firstname,lastname,member_email) VALUES
('$newname','$today',password('$newpass'),
'$firstname','$lastname','$member_email')";
mysql_query($sql);
$auth="yes"; // 150
$logname = $newname; // 151
}
?>
btw.. the switch statement at the top is there cos I want to add a member login for existing members and so need that for the new section.
Thanks
luds
But now I'm stuck!
When the simple form is filled in, the page just losed the info typed in and has
"already used. Select another member ID." at the top of the page.
I can see that it should have the visitors new ID written before it... but can't find the error in the script!
Here's the form:
<html>
<?php
/* File: login_form_test.php
* Desc: Displays login page. Page displays one form to provide
the information needed to apply for a new account.
*/ // 7
?>
<!-- form for new member to fill in -->
<form action="login_test.php?do=new" method="post">
<input type="hidden" name="do" value="new">
<p>
<table border="0" width="100%">
<?php
if (isset($message_new)) // 48
echo "<tr><td colspan='2'><b>$message_new</b></td></tr>";
?>
<tr>
<td align="right"><b>Member ID</b></td>
<td><input type="text" name="newname"
value="<?php echo $newname ?>"
size="20" maxlength="20"></td>
</tr>
<tr>
<td align="right"><b>Password</b></td>
<td><input type="password" name="newpass"
value="<?php echo $newpass ?>"
size="10" maxlength="8"></td>
</tr>
<tr>
<td align="right"><b>First Name</b></td>
<td><input type="text" name="firstname"
value="<?php echo $firstname ?>"
size="40" maxlength="40"></td>
</tr>
<tr>
<td align="right"><b>Last Name</b></td>
<td><input type="text" name="lastname"
value="<?php echo $lastname ?>"
size="40" maxlength="40"></td>
</tr>
<tr>
<td align=right><b>Email Address</b></td>
<td><input type="test" name="email" value="<?php echo $email ?>"
size="55" maxlength="67"></td>
</tr>
<tr>
<td> </td>
<td align="center"> <input type="submit" value="Become a Member"></td>
</tr>
</table>
</form>
</td>
</tr>
<tr><td colspan="3" bgcolor="gray"> </td></tr>
</table>
</body>
</html>
............ and the php script to accompany it...
<?php
/* Program: Login.php
Desc: Login program for the Members Only section of the
site. Enter a new login name. Login
Names, passwords and details are stored in a MySQL database.
*/
session_start(); // 8
session_register('auth'); // 9
session_register('logname');
include("access.php"
switch (@$do) // 12
{
case "new": // 60
foreach($HTTP_POST_VARS as $key => $value) // 61
if (ereg("{Name)",$key)) // 74
{
if (!ereg("^[A-Za-z' -]{1,50}$",$key))
{
unset($do);
$message_new = "$lastname is not a valid name.
Please try again.";
include("login_form_test.php"
exit();
}
}
$$key = strip_tags(trim($value)); // 85
}
/* check to see if login name already exists */
$connection = mysql_connect($host,$user,$password) // 123
or die ("Couldn't connect to server."
$db = mysql_select_db($database, $connection)
or die ("Couldn't select database."
$sql = "SELECT member_ID FROM nmc_site_members
WHERE member_ID='$newname'";
$result = mysql_query($sql)
or die("Couldn't execute query."
$num = mysql_num_rows($result);
if ($num > 0) // 132
{
unset($do);
$message_new = "$newname already used. Select another
member ID.";
include("login_form_test.php"
exit();
}
else // 140
{
$today = time("Y-m-d"
$sql = "INSERT INTO nmc_site_members (member_ID,createdate,password,
firstname,lastname,member_email) VALUES
('$newname','$today',password('$newpass'),
'$firstname','$lastname','$member_email')";
mysql_query($sql);
$auth="yes"; // 150
$logname = $newname; // 151
}
?>
btw.. the switch statement at the top is there cos I want to add a member login for existing members and so need that for the new section.
Thanks
luds