PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Fri Nov 21, 2014 11:15 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: Fri Apr 13, 2012 8:21 am 
Offline
Forum Commoner

Joined: Wed Apr 11, 2012 8:54 am
Posts: 50
Location: United States
Celauran wrote:
Without seeing what line 5 is (and the surrounding lines, really), I can't help you much.


Whoops

Syntax: [ Download ] [ Hide ]
<?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

Syntax: [ Download ] [ Hide ]
if (!empty($_POST))


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

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 3747
Location: Montreal, Canada
You're missing the semicolon after var_dump

_________________
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:24 am 
Offline
Forum Commoner

Joined: Wed Apr 11, 2012 8:54 am
Posts: 50
Location: United States
Celauran wrote:
You're missing the semicolon after var_dump


Well, I'm dumb. :P

Syntax: [ Download ] [ Hide ]
array(2) { ["username"]=> string(0) "" ["password"]=> string(8) "password" }


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

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 3747
Location: Montreal, Canada
So $_POST['username'] is empty, which is why the if fails.

_________________
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:31 am 
Offline
Forum Commoner

Joined: Wed Apr 11, 2012 8:54 am
Posts: 50
Location: United States
So what would that point to? An issue with my HTML markup or an issue with my database?


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

Joined: Wed Apr 11, 2012 8:54 am
Posts: 50
Location: United States
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.

Syntax: [ Download ] [ Hide ]
array(2) { ["username"]=> string(4) "John" ["password"]=> string(8) "password" }


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

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 3747
Location: Montreal, Canada
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.

_________________
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:46 am 
Offline
Forum Commoner

Joined: Wed Apr 11, 2012 8:54 am
Posts: 50
Location: United States
Like this?

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");
    echo'testing';
    }
    else
        die("Incorrect information");
}
   
?>


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

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 3747
Location: Montreal, Canada
Sure. Using your previous form submission, you should see testing echoed.

_________________
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:51 am 
Offline
Forum Commoner

Joined: Wed Apr 11, 2012 8:54 am
Posts: 50
Location: United States
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.


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

Joined: Wed Apr 11, 2012 8:54 am
Posts: 50
Location: United States
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. :P


Syntax: [ Download ] [ Hide ]
<?php

if (!empty($_POST))
{
    if (isset($_POST['username']) && isset($_POST['password']))
    {
    $mysqli = new mysqli();
    $mysqli = new mysqli('localhost', 'root', '', 'tracker');
    }
    else
        die();
}
   
?>


Top
 Profile  
 
 Post subject: Re: Code Issue
PostPosted: Fri Apr 13, 2012 9:47 am 
Online
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 3747
Location: Montreal, Canada
Syntax: [ Download ] [ Hide ]
<?php

if (!empty($_POST))
{
    if (isset($_POST['username']) && isset($_POST['password']))
    {
        $mysqli = new mysqli('localhost', 'root', '', 'tracker');
    }
    else
        die();
}
   
?>

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


Top
 Profile  
 
 Post subject: Re: Code Issue
PostPosted: Fri Apr 13, 2012 9:48 am 
Online
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 3747
Location: Montreal, Canada
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.

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


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

Joined: Wed Apr 11, 2012 8:54 am
Posts: 50
Location: United States
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?

Syntax: [ Download ] [ Hide ]
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".

Syntax: [ Download ] [ Hide ]
else
        die('Unable to proceed');


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

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 3747
Location: Montreal, Canada
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.

_________________
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: cgfgfbfb, Yahoo [Bot] and 16 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