PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun Dec 21, 2014 3:30 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 78 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6  Next
Author Message
 Post subject: Re: Code Issue
PostPosted: Thu Apr 12, 2012 10:02 am 
Offline
Forum Commoner

Joined: Wed Apr 11, 2012 8:54 am
Posts: 50
Location: United States
Celauran wrote:
TheHappyPeanut wrote:
Furthermore, the "Incorrect information" string is still there, even though I 100% used the correct user and password.

What does this give you?
Syntax: [ Download ] [ Hide ]
var_dump($_POST);


There are no changes after placing that into the code. Is there a specific place I need to put it?


Top
 Profile  
 
 Post subject: Re: Code Issue
PostPosted: Thu Apr 12, 2012 10:05 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 3890
Location: Montreal, Canada
You just need to be sure it's executing. May as well place it right at the top. var_dump always produces output.

_________________
Stay on top of upgrades.
Supported PHP versions
No longer supported versions


Top
 Profile  
 
 Post subject: Re: Code Issue
PostPosted: Thu Apr 12, 2012 10:17 am 
Offline
Forum Commoner

Joined: Wed Apr 11, 2012 8:54 am
Posts: 50
Location: United States
I placed it at the top and it worked. I actually figured out my problem; I originally had the text-box use "email-address" when it should have used "username". That brings me to another question. Let's say that I have the following database fields:

- id
- email
- username
- password

How can I make it so that a user can log in if they provide either the email or the username. For example, a person could log in using "John" or "john@example.com".


Top
 Profile  
 
 Post subject: Re: Code Issue
PostPosted: Thu Apr 12, 2012 10:19 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 3890
Location: Montreal, Canada
Absolutely.

Syntax: [ Download ] [ Hide ]
SELECT columnA, columnB FROM users WHERE username = 'provided_username' OR email = 'provided_username'

_________________
Stay on top of upgrades.
Supported PHP versions
No longer supported versions


Top
 Profile  
 
 Post subject: Re: Code Issue
PostPosted: Thu Apr 12, 2012 10:23 am 
Offline
Forum Commoner

Joined: Wed Apr 11, 2012 8:54 am
Posts: 50
Location: United States
Celauran wrote:
Absolutely.

Syntax: [ Download ] [ Hide ]
SELECT columnA, columnB FROM users WHERE username = 'provided_username' OR email = 'provided_username'


So basically, that code saying "Username no longer equal to username. Username is equal to username or password"? And where would that code go? Is there any easy way to learn where I place this code other than trial and error and a lot of reading?


Top
 Profile  
 
 Post subject: Re: Code Issue
PostPosted: Thu Apr 12, 2012 10:28 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 3890
Location: Montreal, Canada
If you recognized that that's SQL and not PHP, then simply use it as a query string (obviously replacing the dummy values with real ones). If not, you will want to become familiar with SQL.

_________________
Stay on top of upgrades.
Supported PHP versions
No longer supported versions


Top
 Profile  
 
 Post subject: Re: Code Issue
PostPosted: Thu Apr 12, 2012 10:37 am 
Offline
Forum Commoner

Joined: Wed Apr 11, 2012 8:54 am
Posts: 50
Location: United States
I did recognize it dealt with MySQL, but I haven't read up on that yet. I'll do that now. I REALLY appreciate your help.


Top
 Profile  
 
 Post subject: Re: Code Issue
PostPosted: Fri Apr 13, 2012 7:44 am 
Offline
Forum Commoner

Joined: Wed Apr 11, 2012 8:54 am
Posts: 50
Location: United States
Would it look something like this?

Syntax: [ Download ] [ Hide ]
$query = mysql_query ("SELECT columnA, columnB FROM users WHERE username = 'username' OR email = 'username'");


Top
 Profile  
 
 Post subject: Re: Code Issue
PostPosted: Fri Apr 13, 2012 7:53 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 3890
Location: Montreal, Canada
Replacing columnA, columnB and 'username' with actual values, yes.

I also find it helpful for debugging to store the query itself as a variable, rather than just the result.
Syntax: [ Download ] [ Hide ]
$query  = "SELECT columnA, columnB FROM users WHERE username = '{$username}' OR email = '{$username}'";
$result = $sql->query($query);

_________________
Stay on top of upgrades.
Supported PHP versions
No longer supported versions


Top
 Profile  
 
 Post subject: Re: Code Issue
PostPosted: Fri Apr 13, 2012 8:06 am 
Offline
Forum Commoner

Joined: Wed Apr 11, 2012 8:54 am
Posts: 50
Location: United States
Celauran wrote:
Replacing columnA, columnB and 'username' with actual values, yes.

I also find it helpful for debugging to store the query itself as a variable, rather than just the result.
Syntax: [ Download ] [ Hide ]
$query  = "SELECT columnA, columnB FROM users WHERE username = '{$username}' OR email = '{$username}'";
$result = $sql->query($query);


So the columns are actually my row values in the database?

Also, it seems as if something else went wrong. It shows a blank page when you log in regardless of whether you put in no information, incorrect information, or correct information.

Syntax: [ Download ] [ Hide ]
<?php

if (!empty($_POST))
{
    if (isset($_POST['username']) && isset($_POST['password']))
    {        
    $connect = mysql_connect("localhost","root","") or die("Could not connect");
    mysql_select_db("tracker") or die("Could not find database");
    }
    else
        die("Incorrect information");    
}
   
?>


Top
 Profile  
 
 Post subject: Re: Code Issue
PostPosted: Fri Apr 13, 2012 8:10 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 3890
Location: Montreal, Canada
TheHappyPeanut wrote:
So the columns are actually my row values in the database?

They're the columns you want returned

TheHappyPeanut wrote:
Also, it seems as if something else went wrong. It shows a blank page when you log in regardless of whether you put in no information, incorrect information, or correct information.

Syntax: [ Download ] [ Hide ]
<?php

if (!empty($_POST))
{
    if (isset($_POST['username']) && isset($_POST['password']))
    {        
    $connect = mysql_connect("localhost","root","") or die("Could not connect");
    mysql_select_db("tracker") or die("Could not find database");
    }
    else
        die("Incorrect information");    
}
   
?>

So you're not even getting the die() message? Try echoing some dummy text at the very top of the page to make sure the page is loading. If not, check your form's action against the page name.

_________________
Stay on top of upgrades.
Supported PHP versions
No longer supported versions


Top
 Profile  
 
 Post subject: Re: Code Issue
PostPosted: Fri Apr 13, 2012 8:12 am 
Offline
Forum Commoner

Joined: Wed Apr 11, 2012 8:54 am
Posts: 50
Location: United States
Yeah, I'm not getting the die() message. I tried echoing and that function works fine.


Top
 Profile  
 
 Post subject: Re: Code Issue
PostPosted: Fri Apr 13, 2012 8:15 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 3890
Location: Montreal, Canada
That would suggest that the first if is failing, meaning $_POST is empty. var_dump($_POST) to confirm.

_________________
Stay on top of upgrades.
Supported PHP versions
No longer supported versions


Top
 Profile  
 
 Post subject: Re: Code Issue
PostPosted: Fri Apr 13, 2012 8:19 am 
Offline
Forum Commoner

Joined: Wed Apr 11, 2012 8:54 am
Posts: 50
Location: United States
This is what I get when I try that:

Syntax: [ Download ] [ Hide ]
Parse error: syntax error, unexpected T_IF in C:\xampp\htdocs\Tracker\login.php on line 5


Top
 Profile  
 
 Post subject: Re: Code Issue
PostPosted: Fri Apr 13, 2012 8:20 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 3890
Location: Montreal, Canada
Without seeing what line 5 is (and the surrounding lines, really), I can't help you much.

_________________
Stay on top of upgrades.
Supported PHP versions
No longer supported versions


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 78 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: Exabot [Bot], Yahoo [Bot] and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group