Jump to content


Photo

php table logic error?


  • Please log in to reply
7 replies to this topic

#1 prongs_386

prongs_386
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 28 July 2006 - 06:43 AM

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]

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 28 July 2006 - 06:57 AM

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




<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>


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 28 July 2006 - 07:00 AM

if this is the problam post the select staement ok

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

$usrname = $nt[user];
if ($usr == $usrname){
$stat = '1';
}
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 prongs_386

prongs_386
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 28 July 2006 - 07:16 AM

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?

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 28 July 2006 - 07:27 AM

get user info from one page and submit to another then redirect to the showing page ok.

1 user info form

post to

page 2 to insert then add a header redirect

then to view page ok.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#6 prongs_386

prongs_386
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 28 July 2006 - 08:08 AM

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?

#7 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 28 July 2006 - 08:21 AM


some think like that lol.....................

$query="delete from xxxxx where usrrec='user1' and userrec='$userrec'";
$result=mysql_query($query);


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#8 prongs_386

prongs_386
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 28 July 2006 - 11:28 AM

err.... that didn't work...

Unknown column 'usrec' in 'where clause'

any other suggestions




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users