This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-06-03 11:37:52

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

PHP Login form for my site

I have this code:

Code:

<html>
    <head>
        <?php include "header.php"; ?>
    </head>
    <body>
        <p>
            <div id="dialog">
                <?php
                    if(isset($_POST['submit'])){
                        $username = $_POST['name'];
                        $password = $_POST['password'];
                        $md5_password = md5($password);
                        if(isset($username)&&isset($password)){
                            $account = mysql_query("SELECT name FROM users WHERE name='$username' AND pass='$md5_password'"); //LINE 14 --- OVER HERE
                            if(mysql_num_rows($account)>0){
                                echo "Successfully logged in.";
                            } else{
                                echo "Wrong username or password.";
                            }
                        } else{
                            echo "Please fill in all the details.";
                        }
                    } else {
                        echo "Login to Mini Universe to get cool site extras!";
                    }
                ?>
            </div>
            <br />
            <form method="post" action="login.php">
                <input type="text" name="name" value="Username" maxlength="25" /><br /><br />
                <input type="text" name="password" value="Password" maxlength="25" /><br /><br />
                <input type="submit" name="submit" value="Login" />
            </form>
        </p>
    </body>
</html>

Its a login form for my site, but it doesn't seem to work at line 14, instead when I try to login with my registered account, I get "Wrong username or password". Help appreciated. Thanks.


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#2 2012-06-03 11:41:37

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Re: PHP Login form for my site

If this is your first time creating a login system, you should try using files instead of MySQL, as it is much easier.

Also, if you are using MySQL, you should use MySQLi instaed.


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#3 2012-06-03 13:46:47

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: PHP Login form for my site

^
|
|
no

BUMP


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#4 2012-06-03 16:41:03

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: PHP Login form for my site

Yea, I need help quick.


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#5 2012-06-03 16:43:04

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Re: PHP Login form for my site

WindowsExplorer wrote:

^
|
|
no

BUMP

What?


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#6 2012-06-03 20:43:01

jji7skyline
Scratcher
Registered: 2010-03-08
Posts: 1000+

Re: PHP Login form for my site

I agree with jvvg.

Or you could use SQlite which is supposed to be easier.


I don't know why you say goodbye, I say hello!  big_smile

Offline

 

#7 2012-06-03 21:01:47

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Re: PHP Login form for my site

jji7skyline wrote:

I agree with jvvg.

Or you could use SQlite which is supposed to be easier.

Actually, SQLite is about the same as MySQL in terms of difficulty. The only difference is that the SQLite database is stored locally in a file, and MySQL is on a server. In terms of programming syntax, the queries are exactly the same.

That's why my older sites use files instead of MySQL.


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#8 2012-06-04 03:19:38

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: PHP Login form for my site

Look, when I post a question asking for help, I DON'T want to go off and change it completely and use files, I just want a simple answer. And yes, I have made one before. If your gonna go off topic do it somewhere else.


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#9 2012-06-04 09:51:42

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: PHP Login form for my site

SELECT name FROM users only selects the names. Try using SELECT * FROM users.

Offline

 

Board footer