Jump to content


Photo

Why doesn't this work?! :\


  • Please log in to reply
57 replies to this topic

#41 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 01 August 2006 - 04:55 PM

king arthur was right I was wondering what he was talking about at first.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#42 SilverNova

SilverNova
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 01 August 2006 - 04:55 PM

changed php.ini

; Lifetime in seconds of cookie or, if 0, until browser is restarted.
session.cookie_lifetime = 0

to

; Lifetime in seconds of cookie or, if 0, until browser is restarted.
session.cookie_lifetime = 2400

and test.php now looks like this after taking out the echo:

<?php
session_start();
?>
<?php

$username = $_POST["username"]; //get the username from the form, as $username
$password = md5($_POST["password"]); //get the password from the form in md5

$users = mysql_connect("localhost", "lov3dco_users", "test");
    if(!$users) {
          echo "<p>Sorry! We could not log you in at this time. Please Try again later!</p>";
          exit();
        }
echo "test3";
mysql_select_db("lov3dco_users");  //select what database to use
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$recieve = "SELECT * FROM users WHERE username =  '$username' AND password = '$password';";
$query = mysql_query($recieve) or die("Unable to peform query - " . mysql_error()); //do the query
echo "test4";
if($rows = mysql_num_rows($query)){
    $_SESSION['password'] = $password; //store the users password in a sesions var
    $_SESSION['username'] = $username; //store the username in a session var
$page = "index.php";    

header('Location: ' . $page);
}else {
echo "test6";
    session_destroy(); 
}


?>

Still blank, apart from the echo's - http://lov3d.com/test.htm

#43 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 01 August 2006 - 04:57 PM

You have a bunch of echos which is why your code is not working try this:
<?php
session_start();

$username = $_POST["username"]; //get the username from the form, as $username
$password = md5($_POST["password"]); //get the password from the form in md5

$users = mysql_connect("localhost", "lov3dco_users", "test");
    if(!$users) {
          echo "<p>Sorry! We could not log you in at this time. Please Try again later!</p>";
          exit();
        }

mysql_select_db("lov3dco_users");  //select what database to use
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$recieve = "SELECT * FROM users WHERE username =  '$username' AND password = '$password';";
$query = mysql_query($recieve) or die("Unable to peform query - " . mysql_error()); //do the query

if($rows = mysql_num_rows($query)){
    $_SESSION['password'] = $password; //store the users password in a sesions var
    $_SESSION['username'] = $username; //store the username in a session var
$page = "index.php";

header('Location: ' . $page);
}else {
    session_destroy();
}

?>


#44 SilverNova

SilverNova
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 01 August 2006 - 05:00 PM

Ok, test.php now looks exactly like the above and returns a blank page..

Think businessman just put them in earlier to differentiate what was going on

#45 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 01 August 2006 - 05:04 PM

Okay so something is failing somewhere.

Chnage this:
if($rows = mysql_num_rows($query)){
    $_SESSION['password'] = $password; //store the users password in a sesions var
    $_SESSION['username'] = $username; //store the username in a session var
$page = "index.php";

header('Location: ' . $page);
}else {
    session_destroy();
}
to this:
if($rows = mysql_num_rows($query)){
    echo "login successful";
}else {
    echo "login failed";
}
Do you get anythink now?

#46 SilverNova

SilverNova
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 01 August 2006 - 05:09 PM

Yeah, "login failed"

Here's my table just in case..

Posted Image

#47 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 01 August 2006 - 05:13 PM

Change
if($rows = mysql_num_rows($query)){

to
if(mysql_num_rows($query) == '1'){

What does that produce?

#48 SilverNova

SilverNova
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 01 August 2006 - 05:16 PM

try again - i got parse error = the echo, login successful

I know you mean "if" obviously.. :P

#49 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 01 August 2006 - 05:22 PM

I had a typo before, it should of been this:
if(mysql_num_rows($query) == '1'){
Are you getting login successfull now?
If you are you can replace:
if(mysql_num_rows($query) == '1'){
    echo "login successful";
}else {
    echo "login failed";
}
with:
if(mysql_num_rows($query) == '1')
{
    $_SESSION['password'] = $password; //store the users password in a sesions var
    $_SESSION['username'] = $username; //store the username in a session var

    header('Location: index.php');
}
else
{
    session_destroy();

    echo "login failed, please try again";
}


#50 SilverNova

SilverNova
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 01 August 2006 - 05:29 PM

Nope. sorry  :-\

<?php
session_start();

$username = $_POST["username"]; //get the username from the form, as $username
$password = md5($_POST["password"]); //get the password from the form in md5

$users = mysql_connect("localhost", "lov3dco_users", "test");
    if(!$users) {
          echo "<p>Sorry! We could not log you in at this time. Please Try again later!</p>";
          exit();
        }

mysql_select_db("lov3dco_users");  //select what database to use
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$recieve = "SELECT * FROM users WHERE username =  '$username' AND password = '$password';";
$query = mysql_query($recieve) or die("Unable to peform query - " . mysql_error()); //do the query

if(mysql_num_rows($query) == '1'){
    echo "login successful";
}else {
    echo "login failed";
}

?>

gives login failed

#51 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 01 August 2006 - 05:46 PM

Okay run this:
<?php
session_start();

$conn = mysql_connect("localhost", "lov3dco_users", "test") or die('Unable to connect to MySQL');

// select what database to use
mysql_select_db("lov3dco_users", $conn) or die('Unable to select database - lov3dco_users');

// get the username from the form, as $username
$username = mysql_real_escape_string($_POST['username']);

// get the password from the form in md5
$password = md5($_POST['password']);

$recieve = "SELECT * FROM users WHERE username='$username' AND `password`='$password'";
$query = mysql_query($recieve, $conn) or die("Unable to peform query - " . mysql_error()); //do the query

if(mysql_num_rows($query) == '1')
{
    echo "login successful";
}
else
{
    echo "login failed";
}

echo "<br /><br /><b>DEBUG INFO:</b><br />
<code><b>Username</b>: {$username}<br />
<b>Password</b>: {$_POST['password']}<br />
<b>Password Hash</b>: {$password}<br />
<b>MD5 Hash of 'test'</b>: " . md5('test') . "<br />
<b>MD5 Hash TEST</b>: " . ((md5('test') == $password) ? 'passed' : 'failed') . "<br />
<b>Query</b>: {$recieve}<br />
</code>";

?>
This time it gives you some debug info.Post the debug info it produces here.

#52 SilverNova

SilverNova
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 01 August 2006 - 05:52 PM

login failed

DEBUG INFO:
Username: test
Password: tets
Password Hash: 45edd741812abf42a7b799a6fc558d9c
MD5 Hash of 'test': 098f6bcd4621d373cade4e832627b4f6
MD5 Hash TEST: failed
Query: SELECT * FROM users WHERE username='test' AND `password`='45edd741812abf42a7b799a6fc558d9c'

TETS?! this means..?

#53 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 01 August 2006 - 05:53 PM

You are using the incorrect password. The password you want to use is test and not tets

The DEBUG is what I create with login scripts when they dont work etc. It just shows whats going on.

#54 SilverNova

SilverNova
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 01 August 2006 - 05:58 PM

Argh omw, was filling it in automatically for a while using FF... but now that it's resolved -

what script can i finally use?! :D

Many thanks for all your help - i'll be sure to link back to you from all my sites in future!!  ;D

#55 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 01 August 2006 - 06:04 PM

Change this:
if(mysql_num_rows($query) == '1')
{
    echo "login successful";
}
else
{
    echo "login failed";
}

echo "<br /><br /><b>DEBUG INFO:</b><br />
<code><b>Username</b>: {$username}<br />
<b>Password</b>: {$_POST['password']}<br />
<b>Password Hash</b>: {$password}<br />
<b>MD5 Hash of 'test'</b>: " . md5('test') . "<br />
<b>MD5 Hash TEST</b>: " . ((md5('test') == $password) ? 'passed' : 'failed') . "<br />
<b>Query</b>: {$recieve}<br />
</code>";
to this:
if(mysql_num_rows($query) == '1')
{
    $_SESSION['password'] = $password; //store the users password in a sesions var
    $_SESSION['username'] = $username; //store the username in a session var

    header('Location: index.php');
}
else
{
    session_destroy();

    echo "login failed, please try again";
}

and you should be set to go, fingers crossed

#56 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 01 August 2006 - 06:06 PM

I am back I am glad you 2 figured it out and everything is running now.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#57 SilverNova

SilverNova
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 01 August 2006 - 06:24 PM

WOOOO Thanks guys, very very much appreciated  ;D ;D

#58 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 01 August 2006 - 06:25 PM

thanks too wildteen for the debug thing, that'll help too later.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users