Jump to content

php table logic error?


prongs_386

Recommended Posts

Hi, my code bassically allows a user to add their username by clicking a button. (the username is given through a phpbb function)
A table is then displayed with al the results. This is working fine, but my error has come up when trying to stop users registering if they already exist on the database. I did this by having a loop which will set $stat = '1'; only if the userrname is the same, people can only press the register button while $stat = '0';
The problem is, $stat never seems to be set to 1, even though i know both values which i am comparing are equal. I echo them both and they are both the same, but my if ($usr == $username){ $stat = '1';} never seems to get through
I have attached my code.
Please help
P.S. I know its a mess ;)

[attachment deleted by admin]
Link to comment
Share on other sites

lets all of us have a look lol........................



[code]

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="black" text="#2370B6">
Please refresh this page after you register!
<form method="POST" action="">
<INPUT type="submit" name="reg1" value="Register">
<br>

<?php

define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//

$usrnum = '1';
//$stat = '0';
$usr = $userdata['username'];


include 'includes/config2.php';
include 'includes/opendb.php';


$dbh="select * from lan";
$us=mysql_query($dbh);




echo '<table border="3" cellpadding="3">';
echo '<tr><td><b>User</b></td><td><b>Registered</b></td><td><b>Confirmed</b></td><td><b>Number</b></td>';
echo '</tr>';




while($nt=mysql_fetch_array($us)){

$usrname = $nt[user];
$usrconf = $nt[conf];

include 'includes/disptbl.php';
$usrnum = $usrnum + 1;
}


include 'includes/closedb.php';



echo '</table>';



if($_POST['reg1'] == "Register")
{

if($usrnum != 61){
include 'includes/config2.php';
include 'includes/opendb.php';


while($nt=mysql_fetch_array($us)){

$usrname = $nt[user];
if ($usr == $usrname){
$stat = '1';
}

}

if ($stat != '1'){
include 'includes/insert.php';
}


include 'includes/closedb.php';
}
}
echo $stat;
echo $usr;
echo $usrname;
if($usrnum == 61){
echo 'Sorry, we are full up!';
}

?>

</body>
<html>

[/code]
Link to comment
Share on other sites

ok, thanx for the quick replies.
But i just managed to solve it! the solution didnt make sense to me in relation to the behaviour but what i did was remove the second while statement and put the if statement in the first 1(the statement which sets $stat = 1)

my other problem is though, my register function happens after the display function, so if a user successfully registers, their name wont appear untill the next refresh.

how can i insert a bit of code that will just load the page again?
Link to comment
Share on other sites

thankyou redarrow, I will try that.

I have one last query, i have written a section that will call an unregister page and this page must call delete on a sql database.
the first collumn is user for usernames, and the second is conf for confirmation status.
I have a variable $usrrec that holds the username which i want to remove eg 'user1' and i want to delete the row in which user has an entry of 'user1'
How can i do this?
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.