Page 3 of 6
Re: Code Issue
Posted: Fri Apr 13, 2012 8:21 am
by TheHappyPeanut
Celauran wrote:Without seeing what line 5 is (and the surrounding lines, really), I can't help you much.
Whoops
Code: Select all
<?php
var_dump($_POST)
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");
}
?>
Line 5 being
Re: Code Issue
Posted: Fri Apr 13, 2012 8:23 am
by Celauran
You're missing the semicolon after var_dump
Re: Code Issue
Posted: Fri Apr 13, 2012 8:24 am
by TheHappyPeanut
Celauran wrote:You're missing the semicolon after var_dump
Well, I'm dumb.
[text]array(2) { ["username"]=> string(0) "" ["password"]=> string(8) "password" }[/text]
Re: Code Issue
Posted: Fri Apr 13, 2012 8:25 am
by Celauran
So $_POST['username'] is empty, which is why the if fails.
Re: Code Issue
Posted: Fri Apr 13, 2012 8:31 am
by TheHappyPeanut
So what would that point to? An issue with my HTML markup or an issue with my database?
Re: Code Issue
Posted: Fri Apr 13, 2012 8:33 am
by TheHappyPeanut
Actually, that's a flawed output because I didn't put anything in the log-in box (if I should have). Here's one where I filled in both fields.
Code: Select all
array(2) { ["username"]=> string(4) "John" ["password"]=> string(8) "password" }
Re: Code Issue
Posted: Fri Apr 13, 2012 8:36 am
by Celauran
That one should work fine. You won't see any output to screen because you haven't done anything that produces any. You can echo some dummy text after selecting your database to confirm it's working if you like.
Re: Code Issue
Posted: Fri Apr 13, 2012 8:46 am
by TheHappyPeanut
Like this?
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");
echo'testing';
}
else
die("Incorrect information");
}
?>
Re: Code Issue
Posted: Fri Apr 13, 2012 8:48 am
by Celauran
Sure. Using your previous form submission, you should see testing echoed.
Re: Code Issue
Posted: Fri Apr 13, 2012 8:51 am
by TheHappyPeanut
Celauran wrote:Sure. Using your previous form submission, you should see testing echoed.
Yes, it's echoing the text when I attempt to log in.
Re: Code Issue
Posted: Fri Apr 13, 2012 9:36 am
by TheHappyPeanut
I implemented mysqli a few minutes ago and I've not received any errors, so I'm assuming I've done it correctly. With that being said, the issue I'm having still exists.
Code: Select all
<?php
if (!empty($_POST))
{
if (isset($_POST['username']) && isset($_POST['password']))
{
$mysqli = new mysqli();
$mysqli = new mysqli('localhost', 'root', '', 'tracker');
}
else
die();
}
?>
Re: Code Issue
Posted: Fri Apr 13, 2012 9:47 am
by Celauran
Code: Select all
<?php
if (!empty($_POST))
{
if (isset($_POST['username']) && isset($_POST['password']))
{
$mysqli = new mysqli('localhost', 'root', '', 'tracker');
}
else
die();
}
?>
Re: Code Issue
Posted: Fri Apr 13, 2012 9:48 am
by Celauran
TheHappyPeanut wrote:With that being said, the issue I'm having still exists.
What issue is that? As per above, everything seems to be working fine given the little code you're written.
Re: Code Issue
Posted: Fri Apr 13, 2012 9:58 am
by TheHappyPeanut
I can type anything I want into the form and it never gives me an error. Perhaps I've left a bit of code out that I require?
Code: Select all
if (isset($_POST['username']) && isset($_POST['password']))
{
$mysqli = new mysqli();
$mysqli = new mysqli('localhost', 'root', '', 'tracker');
}
else
die('Unable to proceed');
If I am correct, then this line of code basically says "If you don't provide me with a correct username or password, I'm closing the connection and telling you "Unable to proceed".
Re: Code Issue
Posted: Fri Apr 13, 2012 10:01 am
by Celauran
It's not performing any authentication. That block, in English, would ready "If a (any) username and password have been provided, open a connection to the database. Otherwise, don't and inform the user you couldn't." Or something to that effect.