Jump to content

Tutorial fail


snallemap

Recommended Posts

Hello Php Freaks

 

I am following this tutorial how to make a login for my website, the only trouble is that... It dosen't seem to work, so i wanna know if its only me who cant make it work... and if it is why XD...

 

Tutorial can be found here:

http://www.knowledgesutra.com/forums/topic/7887-php-simple-login-tutorial/

 

 

Now when i get started it starts saying error at line 6:

        if ($_GET["op"] == "login")

 

It says that when im about to login right above the login.

 

Now when i put in data i get error on line 19:

 

  $r = mysql_query($q);

 

That one, and i have no idea how to fix it.

 

Anyone please :D?

 

Link to comment
Share on other sites

Here is the login.php

 

<?php
        session_start();
        // dBase file
        include "config.php";

        if ($_GET["op"] == "login")
  {
  if (!$_POST["username"] || !$_POST["password"])
        {
        die("You need to provide a username and password.");
        }
  
  // Create query
  $q = "SELECT * FROM `gusers` "
        ."WHERE `username`='".$_POST["username"]."' "
        ."AND `password`=PASSWORD('".$_POST["password"]."') "
        ."LIMIT 1";
  // Run query
  $r = mysql_query($q);

  if ( $obj = @mysql_fetch_object($r) )
        {
        // Login good, create session variables
        $_SESSION["valid_id"] = $obj->id;
        $_SESSION["valid_user"] = $_POST["username"];
        $_SESSION["valid_time"] = time();

        // Redirect to member page
        Header("Location: members.php");
        }
  else
        {
        // Login not successful
        die("Sorry, could not log you in. Wrong login information.");
        }
  }
        else
  {
//If all went right the Web form appears and users can log in
  echo "<form action=\"?op=login\" method=\"POST\">";
  echo "Username: <input name=\"username\" size=\"15\"><br />";
  echo "Password: <input type=\"password\" name=\"password\" size=\"8\"><br />";
  echo "<input type=\"submit\" value=\"Login\">";
  echo "</form>";
  }
        ?>

 

When i open the login.php it says:

 

Notice: Undefined index: op in C:\wamp\www\kawaii\login.php on line 6

 

Above the actual login..

 

When i write in the code and tries to login i get:

 

Warning: mysql_query() [function.mysql-query]: Access denied for user 'SYSTEM'@'localhost' (using password: NO) in C:\wamp\www\kawaii\login.php on line 19

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\wamp\www\kawaii\login.php on line 19
Sorry, could not log you in. Wrong login information.

 

Please help :(

Link to comment
Share on other sites

<?
$host = "localhost";
$user = "root";
$pass = "test123";
$db   = "kawaii";


$ms = mysql_pconnect($host, $user, $pass);
if ( !$ms )
        {
        echo "Error connecting to database.\n";
        }


mysql_select_db($db);
?>

 

 

This is my config that i link to though login.php using include.... Is there any wrong things in it ?.. If so what is it :/

Link to comment
Share on other sites

<?
$host = "localhost";
$user = "root";
$pass = "test123";
$db   = "kawaii";


$ms = mysql_pconnect($host, $user, $pass);
if ( !$ms )
        {
        echo "Error connecting to database.\n";
        }


mysql_select_db($db);
?><br />
<b>Notice</b>:  Undefined index: op in <b>C:\wamp\www\kawaii\login.php</b> on line <b>6</b><br />
<form action="?op=login" method="POST">Username: <input name="username" size="15"><br />Password: <input type="password" name="password" size="8"><br /><input type="submit" value="Login"></form>

 

I took your word to me and made the config longer, now it works... but i still have the :

Notice: Undefined index: op in C:\wamp\www\kawaii\login.php on line 6

on the loginpage which is really annoying... i dunno how to get that away.

Link to comment
Share on other sites

After testing it... It seems that login dosen't work anyways... if i enter the right login it still says that the login was wrong. This might be caused by the error on line 6?

 

 

I got errors on my login page, but the login error was caused by too short password lenght (ruined the encrypted password) - Fixed already.

 

I hope someone can help me with the login error on line 6 though

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.