prongs_386 Posted July 28, 2006 Share Posted July 28, 2006 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 throughI have attached my code.Please helpP.S. I know its a mess ;) [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/15861-php-table-logic-error/ Share on other sites More sharing options...
redarrow Posted July 28, 2006 Share Posted July 28, 2006 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><?phpdefine('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] Quote Link to comment https://forums.phpfreaks.com/topic/15861-php-table-logic-error/#findComment-65026 Share on other sites More sharing options...
redarrow Posted July 28, 2006 Share Posted July 28, 2006 if this is the problam post the select staement okwhile($nt=mysql_fetch_array($us)){$usrname = $nt[user];if ($usr == $usrname){$stat = '1';} Quote Link to comment https://forums.phpfreaks.com/topic/15861-php-table-logic-error/#findComment-65027 Share on other sites More sharing options...
prongs_386 Posted July 28, 2006 Author Share Posted July 28, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/15861-php-table-logic-error/#findComment-65029 Share on other sites More sharing options...
redarrow Posted July 28, 2006 Share Posted July 28, 2006 get user info from one page and submit to another then redirect to the showing page ok.1 user info formpost to page 2 to insert then add a header redirectthen to view page ok. Quote Link to comment https://forums.phpfreaks.com/topic/15861-php-table-logic-error/#findComment-65032 Share on other sites More sharing options...
prongs_386 Posted July 28, 2006 Author Share Posted July 28, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/15861-php-table-logic-error/#findComment-65040 Share on other sites More sharing options...
redarrow Posted July 28, 2006 Share Posted July 28, 2006 some think like that lol.....................$query="delete from xxxxx where usrrec='user1' and userrec='$userrec'";$result=mysql_query($query); Quote Link to comment https://forums.phpfreaks.com/topic/15861-php-table-logic-error/#findComment-65045 Share on other sites More sharing options...
prongs_386 Posted July 28, 2006 Author Share Posted July 28, 2006 err.... that didn't work...Unknown column 'usrec' in 'where clause'any other suggestions Quote Link to comment https://forums.phpfreaks.com/topic/15861-php-table-logic-error/#findComment-65098 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.