Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
registration script help
Old 07-17-2006, 06:14 PM registration script help
Extreme Talker

Posts: 217
Trades: 0
PHP Code:
$sql2 "SELECT * FROM $usertable WHERE username = $username)";
$result mysql_query($sql2);


//checks to see if they let anything blank
if($username == "" or $password "" or $email == ""){
echo 
"You left something blank! Go back and try again";
}

//checks to see if the username exists
if($result){
echo 
"Username is taken. Please choose a new one."
Having trouble with the secong if statement that checks to see if the username exists. I think its something to do with the $sql2 variable. Should be fairly easy to correct... When i test it out, even though the usernames, passwords and emails are all the same, it still goes to the else statement and adds them to the userbase, instead of stopping them at the second if statement. :S

Last edited by Slick Nick; 07-17-2006 at 06:16 PM..
Slick Nick is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-17-2006, 06:48 PM Re: registration script help
Super Talker

Posts: 111
Name: Jonathan
Location: Arizona, USA
Trades: 0
Quote:
Originally Posted by Slick Nick
//checks to see if they let anything blank
if($username == "" or $password = "" or $email == ""){
echo "You left something blank! Go back and try again";
}
I see a missing "=" in there. Should be:
if($username=="" or $password=="" or $email==""){

That's a start. Hope it helps.
__________________

Please login or register to view this content. Registration is FREE
- Computer Repair over the internet!
pcoptimized is offline
Reply With Quote
View Public Profile Visit pcoptimized's homepage!
 
Old 07-17-2006, 07:22 PM Re: registration script help
Extreme Talker

Posts: 217
Trades: 0
ah, that sort of fixed it. But now no matter what i says that i left something blank, even when nothing is blank! :S also for some reason passwords dont show up in the database. Dono if its supposed to do that or not.

I have another problem to. For my login script (all this stuff im doing is for learning by the way) it always says that the password/name combo is blank...

PHP Code:
                $sql "SELECT username, password FROM $usertable WHERE username='$username' AND password='$password'";
                
$result mysql_query($sql);
                
$rows mysql_fetch_array($result);
                
$count mysql_num_rows($result);

                
//check to see if they logged in right
                
if($count == 0){
                        echo 
"Your username and password combo was incorrect. Please go back and try again";
                }
                
//see if they left anything blank
                
elseif($username == "" or $password == ""){
                        echo 
"You left something blank! go back and try again";
                }
                
//log them in
                
else {
                        
session_start();
                        
$_SESSION['username'] = $username;

                        echo 
"You have been logged in successfuly. Click <a href=index.php>here</a> to go back to the main page"
Thanks for replying
Slick Nick is offline
Reply With Quote
View Public Profile
 
Old 07-17-2006, 08:07 PM Re: registration script help
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Are you sure that the variables $username and $password is defined? If they are passed through the post header or the url, they typically will not be assigned automatically to standard variables unless the register globals is turned on (which is a security issue so the default is off).

You can make sure you define these variables by adding above your sample:
$username = $_POST['username'];
$password = $_POST['password'];
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 07-17-2006, 08:20 PM Re: registration script help
Extreme Talker

Posts: 217
Trades: 0
Quote:
Originally Posted by mgraphic
Are you sure that the variables $username and $password is defined? If they are passed through the post header or the url, they typically will not be assigned automatically to standard variables unless the register globals is turned on (which is a security issue so the default is off).

You can make sure you define these variables by adding above your sample:
$username = $_POST['username'];
$password = $_POST['password'];
yup, those are defined. I just didnt include them in the little code snippet. They are right above the code
Slick Nick is offline
Reply With Quote
View Public Profile
 
Old 07-17-2006, 08:30 PM Re: registration script help
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Try troubleshooting by echoing your variables to see if they actually hold a value. You can also view the elements in an array by using: print_r($_POST);
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 07-17-2006, 09:28 PM Re: registration script help
Super Talker

Posts: 111
Name: Jonathan
Location: Arizona, USA
Trades: 0
How about echo'ing out your query as well, to see what it's querying.
After $count = mysql_num_rows($result);
Code:
echo $sql;
exit();
__________________

Please login or register to view this content. Registration is FREE
- Computer Repair over the internet!
pcoptimized is offline
Reply With Quote
View Public Profile Visit pcoptimized's homepage!
 
Old 07-17-2006, 09:42 PM Re: registration script help
Extreme Talker

Posts: 217
Trades: 0
I did that and the email and username stuff showed up, but not the password. Looked through the code and found out that $password was actually $pasword. Forgot to put an S

Now i have a problem with the code that checks to see if the username exists

PHP Code:
                $sql2 "SELECT username FROM $usertable WHERE username = $username";
                
$result mysql_query($sql2);
                
$count mysql_num_rows($result);


                
//checks to see if they let anything blank
                
if($username == "" or $password == "" or $email == ""){
                        echo 
"You left something blank! Go back and try again";
                }

                
//checks to see if the username exists
                
elseif($count >= 1){
                        echo 
"Username is taken. Please choose a new one."
I get this error:
Quote:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/mugman1/public_html/evilgeniusstudios/test2/sqlClass.php on line 18
I dont get it. It works for my login script (sort of) but it doesnt work for the registration

by the way pcoptimized, did that and its doing everything right. I found out that passwords wernt being added to the database because i mispelled the $password variable. Works now except i get a session error

Quote:

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/mugman1/public_html/evilgeniusstudios/test2/index.php:5) in /home/mugman1/public_html/evilgeniusstudios/test2/sqlClass.php on line 66

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/mugman1/public_html/evilgeniusstudios/test2/index.php:5) in /home/mugman1/public_html/evilgeniusstudios/test2/sqlClass.php on line 66


Last edited by Slick Nick; 07-17-2006 at 09:51 PM..
Slick Nick is offline
Reply With Quote
View Public Profile
 
Old 07-18-2006, 12:22 AM Re: registration script help
Super Talker

Posts: 111
Name: Jonathan
Location: Arizona, USA
Trades: 0
It's kinda hard to tell without knowing what's on line 66 of your sqlClass.php file. But since you say it works on your login script, but not on your registration script, it sounds like to me that you have some <html> lines before your <? php ?> lines in the header. "headers already sent" usually means there is html code before your session information. Try moving all html coding below your session (login functions).
__________________

Please login or register to view this content. Registration is FREE
- Computer Repair over the internet!
pcoptimized is offline
Reply With Quote
View Public Profile Visit pcoptimized's homepage!
 
Old 07-18-2006, 12:35 AM Re: registration script help
Extreme Talker

Posts: 217
Trades: 0
line 66 is the session_start(); function. I remember now that session_start(); has to be above any html. All html seems to be underneath at the moment. But does session_start(); have to be above all php too?

All the main scripts are in the form of functions, in one big class. (one class so far anyways). For the login/registration scripts i just do some if statements then run the appropriate function. Not sure if that has anything to do with it
Slick Nick is offline
Reply With Quote
View Public Profile
 
Old 07-18-2006, 01:11 AM Re: registration script help
Super Talker

Posts: 111
Name: Jonathan
Location: Arizona, USA
Trades: 0
Yes, session_start() must be the first line in your php page. Can't have anything above it. (except <? )
__________________

Please login or register to view this content. Registration is FREE
- Computer Repair over the internet!
pcoptimized is offline
Reply With Quote
View Public Profile Visit pcoptimized's homepage!
 
Old 07-18-2006, 01:40 AM Re: registration script help
Extreme Talker

Posts: 217
Trades: 0
ah yes i fixed that problem.

Now I have another problem thats probably really simple...On the part of the script that actualy logs them in, i have this

PHP Code:
                else {
                        
$_SESSION['username'] = $username;
                        echo 
$username;
                        echo 
", You have been logged in successfuly. Click <a href=index.php>here</a> to go back to the main page";
                } 
It all seems to be working fine. $username prints out how its supposed to. Only problem is no data seems to be entered into the session...

***EDIT*** yay! I fixed the problem for the login page. Didnt know you had to have session_start(); on every page

Last edited by Slick Nick; 07-18-2006 at 01:58 AM..
Slick Nick is offline
Reply With Quote
View Public Profile
 
Old 07-18-2006, 12:39 PM Re: registration script help
Super Talker

Posts: 111
Name: Jonathan
Location: Arizona, USA
Trades: 0
Great. Glad to see you got it working!
__________________

Please login or register to view this content. Registration is FREE
- Computer Repair over the internet!
pcoptimized is offline
Reply With Quote
View Public Profile Visit pcoptimized's homepage!
 
Reply     « Reply to registration script help
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.39097 seconds with 12 queries