Return to iWEBTOOL

Go Back   iWEBTOOL Talk > The Web and your Website > Programming > PHP
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 
Welcome to iWEBTOOL Talk, where you talk about webmaster-related stuff.
 
Discuss topics which interest you.
With over thousands of threads (topics), we're sure you'll find something that'll interest you.
Ask for help whenever you need it.
We have thousands of members who are available to help you if you need it.
It's absolutely FREE!

 1  Register           2  Browse the board           3  Discuss whatever may interest you!
 


Closed Thread
 
Thread Tools Search this Thread Display Modes
Old 11-09-2007, 08:35 PM   #1
LordOrange
Newcomer
 
LordOrange's Avatar
 
Join Date: Nov 2007
Posts: 13
LordOrange is on a distinguished road
Default SQL recall

I've been having some trouble with my loggin script (bellow). It never finds the password out of the databasse so it eather always takes the if in the if.. else or the else indiferent to what the input password is. Could anyone help me...?



<?php
$username="LordOrange";
$con = mysql_connect("mysql3.freehostia.com","benmivl61_m y data","LordRocks");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("benmil61_mydata", $con);
$result = mysql_query("SELECT * FROM reviews WHERE usernames='LordOrange'");
while($row = @mysql_fetch_array($result))
{
echo $row["password"];
}
$password = $row["password"];
echo $password . "<br>";
echo $_POST["password"] . "<br>";
if ($password == $_POST["password"])
echo "<a href='movies-edit.php'>Continue</a>";
else
echo "Incorrect username or password";
?>

Last edited 11-10-2007 at 06:47 AM.
LordOrange is offline  
 
This is an Ad Revenue Sharing forum Place your advert here
SEO Checklist
Get yourself better ranking with
our "Do-it-Yourself" SEO Checklist.
Click Here
Old 11-10-2007, 12:27 AM   #2
UnKnown
Moderator
 
UnKnown's Avatar
 
Join Date: Aug 2006
Posts: 1,134
UnKnown is just really niceUnKnown is just really niceUnKnown is just really niceUnKnown is just really niceUnKnown is just really nice
Default Re: SQL recall

The while loop is

try this

Quote:
<?php
$username="LordOrange";
$con = mysql_connect("mysql3.freehostia.com","benmil61_my data","LordOrangeRocks");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("benmil61_mydata", $con);
$result = mysql_query("SELECT * FROM reviews WHERE usernames='LordOrange'");
while($row = @mysql_fetch_array($result))
{
echo $row["password"];
}
$password = $row["password"];
echo "$password ".$_POST['password']." ";
if ($password == $_POST["password"])
echo "<a href='movies-edit.php'>Continue</a>";
else
echo "Incorrect username or password";

?>
UnKnown is offline  
Old 11-10-2007, 06:48 AM   #3
LordOrange
Newcomer
 
LordOrange's Avatar
 
Join Date: Nov 2007
Posts: 13
LordOrange is on a distinguished road
Default Re: SQL recall

It still goes with the else statement the whole time and isn't writing anything for the password from the database.
LordOrange is offline  
Old 11-10-2007, 04:09 PM   #4
UnKnown
Moderator
 
UnKnown's Avatar
 
Join Date: Aug 2006
Posts: 1,134
UnKnown is just really niceUnKnown is just really niceUnKnown is just really niceUnKnown is just really niceUnKnown is just really nice
Default Re: SQL recall

lets see the database

whats the point of the while loop?

It loops to the last password
UnKnown is offline  
Old 11-10-2007, 05:59 PM   #5
LordOrange
Newcomer
 
LordOrange's Avatar
 
Join Date: Nov 2007
Posts: 13
LordOrange is on a distinguished road
Default Re: SQL recall

The loop was just the only way I could get it to work
LordOrange is offline  
Old 11-11-2007, 04:18 AM   #6
Intripita-MH
Senior Member
 
Intripita-MH's Avatar
 
Join Date: Sep 2006
Posts: 280
Intripita-MH is a splendid one to beholdIntripita-MH is a splendid one to beholdIntripita-MH is a splendid one to beholdIntripita-MH is a splendid one to beholdIntripita-MH is a splendid one to beholdIntripita-MH is a splendid one to beholdIntripita-MH is a splendid one to beholdIntripita-MH is a splendid one to behold
Send a message via AIM to Intripita-MH Send a message via MSN to Intripita-MH Send a message via Yahoo to Intripita-MH
Default Re: SQL recall

The loop is correct.

I would recommend not doubling up on variable names even though they are in different scopes (post and local) - in other words, $_POST['password'] and $password is a bad idea, especially with register_globals on.

It looks like that setting IS on and thus $password ALWAYS == $password. Rename your variables.
__________________
Intripita :: web hosting | development | conferencing

Business-Grade Web Hosting, Professional Conferencing, Effective Web Development by Intripita
Intripita-MH is offline  
Old 11-11-2007, 04:30 AM   #7
LordOrange
Newcomer
 
LordOrange's Avatar
 
Join Date: Nov 2007
Posts: 13
LordOrange is on a distinguished road
Default Re: SQL recall

Thanks, I'll try that
LordOrange is offline  
Old 11-11-2007, 04:44 AM   #8
LordOrange
Newcomer
 
LordOrange's Avatar
 
Join Date: Nov 2007
Posts: 13
LordOrange is on a distinguished road
Default Re: SQL recall

It still alwys goes with the else code. It also doesn't echo $password.
LordOrange is offline  
Old 11-11-2007, 04:46 AM   #9
LordOrange
Newcomer
 
LordOrange's Avatar
 
Join Date: Nov 2007
Posts: 13
LordOrange is on a distinguished road
Default Re: SQL recall

This is my code now

Code:
$result = mysql_query("SELECT * FROM users WHERE username='$user'"); while ($row = @mysql_fetch_array($result)) { echo $row["password"]; } $password = $row["password"]; echo $password . "<br>"; $pass = $_POST['pass']; echo $pass."<br>"; if ($password == $pass) echo "<a href='movies-edit.php'>Continue</a>"; else echo "Incorrect username or password";

Last edited 11-11-2007 at 05:21 AM.
LordOrange is offline  
Old 11-11-2007, 06:30 PM   #10
LordOrange
Newcomer
 
LordOrange's Avatar
 
Join Date: Nov 2007
Posts: 13
LordOrange is on a distinguished road
Default Re: SQL recall

I found my problem.... My $row variable wasn't global so I could only use it in the scope of the while loop
LordOrange is offline  
 
This is an Ad Revenue Sharing forum Place your advert here
Webmaster Tools Webmaster Tools Click Here
Closed Thread

(Threads which have no activity for more than 30 days are automatically closed.)



Quick Reply
Message:

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Time to recall your old friends. Webdomain.com Web Hosting 0 07-10-2007 10:46 PM
What? No SQL Section? selectsplat Programming 3 06-14-2007 02:08 AM
Looking for PHP+SQL programmer Rickzkm PHP 6 04-29-2007 05:23 AM
Pet Deaths Prompt Recall of Pet Food lexmarks567 General Talk 4 03-19-2007 11:07 AM
Sql ? pankaj MySQL 5 03-15-2007 08:14 PM


All times are GMT. The time now is 07:52 PM.


Powered by vBulletin v3.6.7 © 2008, Jelsoft Enterprises Ltd. SEO by vBSEO © 2006, Crawlability, Inc.