Code Issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Re: Code Issue

Postby TheHappyPeanut » Fri Apr 13, 2012 8:21 am

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

Re: Code Issue

Postby Celauran » Fri Apr 13, 2012 8:23 am

You're missing the semicolon after var_dump
PHP 5.6 released! August 28, 2014
PSA: PHP 5.3 end of life August 14, 2014.
User avatar
Celauran
Moderator
 
Posts: 3491
Joined: Tue Nov 09, 2010 3:39 pm
Location: Montreal, Canada

Re: Code Issue

Postby TheHappyPeanut » Fri Apr 13, 2012 8:24 am

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" }
TheHappyPeanut
Forum Commoner
 
Posts: 50
Joined: Wed Apr 11, 2012 8:54 am
Location: United States

Re: Code Issue

Postby Celauran » Fri Apr 13, 2012 8:25 am

So $_POST['username'] is empty, which is why the if fails.
PHP 5.6 released! August 28, 2014
PSA: PHP 5.3 end of life August 14, 2014.
User avatar
Celauran
Moderator
 
Posts: 3491
Joined: Tue Nov 09, 2010 3:39 pm
Location: Montreal, Canada

Re: Code Issue

Postby TheHappyPeanut » Fri Apr 13, 2012 8:31 am

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

Re: Code Issue

Postby TheHappyPeanut » Fri Apr 13, 2012 8:33 am

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" }
TheHappyPeanut
Forum Commoner
 
Posts: 50
Joined: Wed Apr 11, 2012 8:54 am
Location: United States

Re: Code Issue

Postby Celauran » Fri Apr 13, 2012 8:36 am

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.
PHP 5.6 released! August 28, 2014
PSA: PHP 5.3 end of life August 14, 2014.
User avatar
Celauran
Moderator
 
Posts: 3491
Joined: Tue Nov 09, 2010 3:39 pm
Location: Montreal, Canada

Re: Code Issue

Postby TheHappyPeanut » Fri Apr 13, 2012 8:46 am

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");
}
   
?>
TheHappyPeanut
Forum Commoner
 
Posts: 50
Joined: Wed Apr 11, 2012 8:54 am
Location: United States

Re: Code Issue

Postby Celauran » Fri Apr 13, 2012 8:48 am

Sure. Using your previous form submission, you should see testing echoed.
PHP 5.6 released! August 28, 2014
PSA: PHP 5.3 end of life August 14, 2014.
User avatar
Celauran
Moderator
 
Posts: 3491
Joined: Tue Nov 09, 2010 3:39 pm
Location: Montreal, Canada

Re: Code Issue

Postby TheHappyPeanut » Fri Apr 13, 2012 8:51 am

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

Re: Code Issue

Postby TheHappyPeanut » Fri Apr 13, 2012 9:36 am

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();
}
   
?>
TheHappyPeanut
Forum Commoner
 
Posts: 50
Joined: Wed Apr 11, 2012 8:54 am
Location: United States

Re: Code Issue

Postby Celauran » Fri Apr 13, 2012 9:47 am

Syntax: [ Download ] [ Hide ]
<?php

if (!empty($_POST))
{
    if (isset($_POST['username']) && isset($_POST['password']))
    {
        $mysqli = new mysqli('localhost', 'root', '', 'tracker');
    }
    else
        die();
}
   
?>
PHP 5.6 released! August 28, 2014
PSA: PHP 5.3 end of life August 14, 2014.
User avatar
Celauran
Moderator
 
Posts: 3491
Joined: Tue Nov 09, 2010 3:39 pm
Location: Montreal, Canada

Re: Code Issue

Postby Celauran » Fri Apr 13, 2012 9:48 am

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.
PHP 5.6 released! August 28, 2014
PSA: PHP 5.3 end of life August 14, 2014.
User avatar
Celauran
Moderator
 
Posts: 3491
Joined: Tue Nov 09, 2010 3:39 pm
Location: Montreal, Canada

Re: Code Issue

Postby TheHappyPeanut » Fri Apr 13, 2012 9:58 am

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');
TheHappyPeanut
Forum Commoner
 
Posts: 50
Joined: Wed Apr 11, 2012 8:54 am
Location: United States

Re: Code Issue

Postby Celauran » Fri Apr 13, 2012 10:01 am

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.
PHP 5.6 released! August 28, 2014
PSA: PHP 5.3 end of life August 14, 2014.
User avatar
Celauran
Moderator
 
Posts: 3491
Joined: Tue Nov 09, 2010 3:39 pm
Location: Montreal, Canada

PreviousNext

Return to PHP - Code

Who is online

Users browsing this forum: Bing [Bot], powerplay_vj and 8 guests