Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script problem

Status
Not open for further replies.

luds

Programmer
Jul 15, 2003
162
GB
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=&quot;login_test.php?do=new&quot; method=&quot;post&quot;>
<input type=&quot;hidden&quot; name=&quot;do&quot; value=&quot;new&quot;>

<p>
<table border=&quot;0&quot; width=&quot;100%&quot;>
<?php
if (isset($message_new)) // 48
echo &quot;<tr><td colspan='2'><b>$message_new</b></td></tr>&quot;;
?>
<tr>
<td align=&quot;right&quot;><b>Member ID</b></td>
<td><input type=&quot;text&quot; name=&quot;newname&quot;
value=&quot;<?php echo $newname ?>&quot;
size=&quot;20&quot; maxlength=&quot;20&quot;></td>
</tr>
<tr>
<td align=&quot;right&quot;><b>Password</b></td>
<td><input type=&quot;password&quot; name=&quot;newpass&quot;
value=&quot;<?php echo $newpass ?>&quot;
size=&quot;10&quot; maxlength=&quot;8&quot;></td>
</tr>
<tr>
<td align=&quot;right&quot;><b>First Name</b></td>
<td><input type=&quot;text&quot; name=&quot;firstname&quot;
value=&quot;<?php echo $firstname ?>&quot;
size=&quot;40&quot; maxlength=&quot;40&quot;></td>
</tr>
<tr>
<td align=&quot;right&quot;><b>Last Name</b></td>
<td><input type=&quot;text&quot; name=&quot;lastname&quot;
value=&quot;<?php echo $lastname ?>&quot;
size=&quot;40&quot; maxlength=&quot;40&quot;></td>
</tr>
<tr>
<td align=right><b>Email Address</b></td>
<td><input type=&quot;test&quot; name=&quot;email&quot; value=&quot;<?php echo $email ?>&quot;
size=&quot;55&quot; maxlength=&quot;67&quot;></td>
</tr>
<tr>
<td>&nbsp;</td>
<td align=&quot;center&quot;> <input type=&quot;submit&quot; value=&quot;Become a Member&quot;></td>
</tr>
</table>
</form>
</td>
</tr>
<tr><td colspan=&quot;3&quot; bgcolor=&quot;gray&quot;>&nbsp;</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(&quot;access.php&quot;); // 11
switch (@$do) // 12
{
case &quot;new&quot;: // 60
foreach($HTTP_POST_VARS as $key => $value) // 61
if (ereg(&quot;{Name)&quot;,$key)) // 74
{
if (!ereg(&quot;^[A-Za-z' -]{1,50}$&quot;,$key))
{
unset($do);
$message_new = &quot;$lastname is not a valid name.
Please try again.&quot;;
include(&quot;login_form_test.php&quot;);
exit();
}
}
$$key = strip_tags(trim($value)); // 85
}




/* check to see if login name already exists */
$connection = mysql_connect($host,$user,$password) // 123
or die (&quot;Couldn't connect to server.&quot;);
$db = mysql_select_db($database, $connection)
or die (&quot;Couldn't select database.&quot;);
$sql = &quot;SELECT member_ID FROM nmc_site_members
WHERE member_ID='$newname'&quot;;
$result = mysql_query($sql)
or die(&quot;Couldn't execute query.&quot;);
$num = mysql_num_rows($result);
if ($num > 0) // 132
{
unset($do);
$message_new = &quot;$newname already used. Select another
member ID.&quot;;
include(&quot;login_form_test.php&quot;);
exit();
}
else // 140
{
$today = time(&quot;Y-m-d&quot;);
$sql = &quot;INSERT INTO nmc_site_members (member_ID,createdate,password,
firstname,lastname,member_email) VALUES
('$newname','$today',password('$newpass'),
'$firstname','$lastname','$member_email')&quot;;
mysql_query($sql);
$auth=&quot;yes&quot;; // 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
 
$sql = &quot;SELECT member_ID FROM nmc_site_members
WHERE member_ID='$newname'&quot;;
echo($sql); //Does this give the correct sql?
$result = mysql_query($sql)
or die(&quot;Couldn't execute query.&quot;);


Known is handfull, Unknown is worldfull
 
vbkris,

Adding that echo($sql); gives me the same result as before, except that I now have

SELECT member_ID FROM nmc_site_members WHERE member_ID=''

at the top of the page>>> then....

already used. select another member ID....followed by the rest of the form.

luds
 
that means ur sql is wrong... that sql is for checking whther a member id exists or not. ther fore it must be like this:
SELECT member_ID FROM nmc_site_members WHERE member_ID='1'

ie $newname is empty.
did u do a Post/Get for it?
$newname=$_POST['newname'];

Known is handfull, Unknown is worldfull
 
vbkris,

When I replace the $newname for a 1, I get...

Warning: Unknown(): Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled.

Any idea what this session side-effect is?? lol

Also,
You asked....
&quot;ie $newname is empty.
did u do a Post/Get for it?
$newname=$_POST['newname']; &quot;

I definately haven't got that line in... is there anywhere imparticular that it should go?

Thanks again
luds
 
yes u need that line. this:
SELECT member_ID FROM nmc_site_members WHERE member_ID='1'
is just an example of what the browser will show u...

and about the next error register_globals is off. please check the line to which the erro points out. if it doesnt then u have to go line by line...


Known is handfull, Unknown is worldfull
 
ok... progress here (I think! lol)

readded the &quot;$newname&quot; to this line,

SELECT member_ID FROM nmc_site_members WHERE member_ID='$newname';

and put

$newname=$_POST['newname']; &quot;

just before the commands to access the mysql db.

Brilliant... if I use an ID already used then that ID name is written into the message &quot;$newname already used. Please select another one&quot; and if it's a unique ID, then it writes it into the db...

but.... (isn't there always one of these! lol)

the other info in the form (firstname, lastname, password and email) are NOT added to the db!

Sorry to be a pain vbkris... but any ideas?

Thanks again

luds
 
simple is there a $_POST['first...'] of all the fields?

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top