There are no changes after placing that into the code. Is there a specific place I need to put it?Celauran wrote:What does this give you?TheHappyPeanut wrote:Furthermore, the "Incorrect information" string is still there, even though I 100% used the correct user and password.Code: Select all
var_dump($_POST);
Code Issue
Moderator: General Moderators
-
TheHappyPeanut
- Forum Commoner
- Posts: 50
- Joined: Wed Apr 11, 2012 8:54 am
- Location: United States
Re: Code Issue
Re: Code Issue
You just need to be sure it's executing. May as well place it right at the top. var_dump always produces output.
-
TheHappyPeanut
- Forum Commoner
- Posts: 50
- Joined: Wed Apr 11, 2012 8:54 am
- Location: United States
Re: Code Issue
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".
- id
- 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".
Re: Code Issue
Absolutely.
Code: Select all
SELECT columnA, columnB FROM users WHERE username = 'provided_username' OR email = 'provided_username'-
TheHappyPeanut
- Forum Commoner
- Posts: 50
- Joined: Wed Apr 11, 2012 8:54 am
- Location: United States
Re: Code Issue
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?Celauran wrote:Absolutely.
Code: Select all
SELECT columnA, columnB FROM users WHERE username = 'provided_username' OR email = 'provided_username'
Re: Code Issue
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.
-
TheHappyPeanut
- Forum Commoner
- Posts: 50
- Joined: Wed Apr 11, 2012 8:54 am
- Location: United States
Re: Code Issue
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.
-
TheHappyPeanut
- Forum Commoner
- Posts: 50
- Joined: Wed Apr 11, 2012 8:54 am
- Location: United States
Re: Code Issue
Would it look something like this?
Code: Select all
$query = mysql_query ("SELECT columnA, columnB FROM users WHERE username = 'username' OR email = 'username'");Re: Code Issue
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.
I also find it helpful for debugging to store the query itself as a variable, rather than just the result.
Code: Select all
$query = "SELECT columnA, columnB FROM users WHERE username = '{$username}' OR email = '{$username}'";
$result = $sql->query($query);-
TheHappyPeanut
- Forum Commoner
- Posts: 50
- Joined: Wed Apr 11, 2012 8:54 am
- Location: United States
Re: Code Issue
So the columns are actually my row values in the database?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.Code: Select all
$query = "SELECT columnA, columnB FROM users WHERE username = '{$username}' OR email = '{$username}'"; $result = $sql->query($query);
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.
Code: Select all
<?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");
}
?>Re: Code Issue
They're the columns you want returnedTheHappyPeanut wrote:So the columns are actually my row values in the database?
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.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.
Code: Select all
<?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"); } ?>
-
TheHappyPeanut
- Forum Commoner
- Posts: 50
- Joined: Wed Apr 11, 2012 8:54 am
- Location: United States
Re: Code Issue
Yeah, I'm not getting the die() message. I tried echoing and that function works fine.
Re: Code Issue
That would suggest that the first if is failing, meaning $_POST is empty. var_dump($_POST) to confirm.
-
TheHappyPeanut
- Forum Commoner
- Posts: 50
- Joined: Wed Apr 11, 2012 8:54 am
- Location: United States
Re: Code Issue
This is what I get when I try that:
[text]Parse error: syntax error, unexpected T_IF in C:\xampp\htdocs\Tracker\login.php on line 5[/text]
[text]Parse error: syntax error, unexpected T_IF in C:\xampp\htdocs\Tracker\login.php on line 5[/text]
Re: Code Issue
Without seeing what line 5 is (and the surrounding lines, really), I can't help you much.