Jump to content

help plz

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
26 replies to this topic

#1
laser212

laser212

    Newbie

  • Members
  • PipPip
  • 25 posts
i am using this script for register login on my website but its not working properly its not posting any of the echo's after the script is run
can anione help me plz

<?php
session_start();
// Check if he wants to login:
if (!empty($_POST[username]))
{
	require_once("connect.php");

	// Check if he has the right info.
	$query = mysql_query("SELECT * FROM members
							WHERE username = '$_POST[username]'
							AND password = '$_POST[password]'")
	or die ("Error - Couldn't login user.");
	
	$row = mysql_fetch_array($query)
	or die ("Error - Couldn't login user.");
	
	if (!empty($row[username])) // he got it.
	{
		$_SESSION[username] = $row[username];
		echo "Welcome $_POST[username]! You've been successfully logged in.";
		exit();
	}
	else // bad info.
	{
		echo "Error - Couldn't login user.<br /><br />
			Please try again.";
		exit();
	}
}

?>

Edited by Orjan, 13 February 2010 - 05:28 AM.
Please use code tags when posting code


#2
Furry Pancake

Furry Pancake

    Learning Programmer

  • Members
  • PipPipPip
  • 54 posts

laser212 said:

i am using this script for register login on my website but its not working properly its not posting any of the echo's after the script is run
can anione help me plz

<?php
session_start();
// Check if he wants to login:
if (!empty($_POST[username]))
{
	require_once("connect.php");

	// Check if he has the right info.
	$query = mysql_query("SELECT * FROM members
							WHERE username = '$_POST[username]'
							AND password = '$_POST[password]'")
	or die ("Error - Couldn't login user.");
	
	$row = mysql_fetch_array($query)
	or die ("Error - Couldn't login user.");
	
	if (!empty($row[username])) // he got it.
	{
		$_SESSION[username] = $row[username];
		echo "Welcome $_POST[username]! You've been successfully logged in.";
		exit();
	}
	else // bad info.
	{
		echo "Error - Couldn't login user.<br /><br />
			Please try again.";
		exit();
	}
}

?>

Are you talking about the actual "Welcome $_POST[username]" echo? or anything after that?

#3
laser212

laser212

    Newbie

  • Members
  • PipPip
  • 25 posts
hi yeah the welcome or the bad login

and if you can show me how to do the 5 sec redirect id realy apreciate it

#4
Furry Pancake

Furry Pancake

    Learning Programmer

  • Members
  • PipPipPip
  • 54 posts
Gotcha, for the refresh, try
<meta http-equiv=refresh content=5; URL=YOURURLHERE>
And that should be your 5 second refresh..

and for the issue..

<?php
session_start();
// Check if he wants to login:
if (!empty($_POST[username]))
{
require_once("connect.php");

// Check if he has the right info.
$query = mysql_query("SELECT * FROM members
WHERE username = '$_POST[username]'
AND password = '$_POST[password]'")
or die ("Error - Couldn't login user.");

$row = mysql_fetch_array($query)
or die ("Error - Couldn't login user.");

if (!empty($row[username])) // he got it.
{
$_SESSION[username] = $row[username];
echo "Welcome $_POST[username]! You've been successfully logged in.";
exit();
}
else // bad info.
{
echo "Error - Couldn't login user.<br /><br />
Please try again.";
exit();
}
}

?>

take out the exit(); and then anything after those should work.. so if you are posting any extra text after that, it will actually load. The "exit();" completely drops the page, so unless you do an include you aren't going to have anything after it.. Make it look like:

<?php
session_start();
// Check if he wants to login:
if (!empty($_POST[username]))
{
require_once("connect.php");

// Check if he has the right info.
$query = mysql_query("SELECT * FROM members
WHERE username = '$_POST[username]'
AND password = '$_POST[password]'")
or die ("Error - Couldn't login user.");

$row = mysql_fetch_array($query)
or die ("Error - Couldn't login user.");

if (!empty($row[username])) // he got it.
{
$_SESSION[username] = $row[username];
echo "Welcome $_POST[username]! You've been successfully logged in.";
}
else // bad info.
{
echo "Error - Couldn't login user.<br /><br />
Please try again.";
}
}

?>

Hopefully that resolves the issue, and if not, try explaining it to me a little differently :P

Oh.. and do you have this posted on the internet?

#5
laser212

laser212

    Newbie

  • Members
  • PipPip
  • 25 posts
thanx it still not working

and no it isnt posted yet im building a cheat website il post the address when i open it

yur welcome to help with some scripts if you want

#6
Furry Pancake

Furry Pancake

    Learning Programmer

  • Members
  • PipPipPip
  • 54 posts
Dammit,
I will research this when I get on my laptop. It is impossible to work through unless I have access to a server. Haha :sneaky:

#7
laser212

laser212

    Newbie

  • Members
  • PipPip
  • 25 posts
000webhost.com
ha ha ha free hosting try it

#8
Furry Pancake

Furry Pancake

    Learning Programmer

  • Members
  • PipPipPip
  • 54 posts

laser212 said:

000webhost.com
ha ha ha free hosting try it
Quote for evidince


is that your website or are you spamming? I think I will report you :thumbdown:

#9
laser212

laser212

    Newbie

  • Members
  • PipPip
  • 25 posts
that just the hosting im using
my website is cheatsrus.info

#10
laser212

laser212

    Newbie

  • Members
  • PipPip
  • 25 posts
hey all i changed that script with a more complicated and secure script but now im getting a bunch of warnings when the registration is complete

can someone help ??
im new to php

Warning: Missing argument 3 for checkUnique(), called in /home/a3445793/public_html/registration.php on line 16 and defined in /home/a3445793/public_html/functions.php on line 17

this is my script on line 16 :

if($_POST['username']!='' && $_POST['password']!='' && $_POST['password']==$_POST['password_confirmed'] && $_POST['email']!='' && valid_email($_POST['email'])==TRUE && checkUnique('Username', $_POST['username'])==TRUE && checkUnique('Email', $_POST['email'])==TRUE)

and on line 17 :

function checkUnique($table, $field, $compared)

next warning :
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a3445793/public_html/functions.php on line 20

and the script :
if(mysql_num_rows($query)==0)

plz help

#11
webcodez

webcodez

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
The way you check a valid login is not totally right or atleast not the way I'd do it. The way I'd check a valid login would be to check whether the mysql query returned any resutls ( which can either be done by using COUNT inside the query or using the function mysql_num_rows ).

Example:

<?php
session_start();
// Check if he wants to login:
if (!empty($_POST[username]))
{
require_once("connect.php");

// Check if he has the right info.
$query = mysql_query("SELECT * FROM members
WHERE username = '".mysql_real_escape_string($_POST[username])."'
AND password = '".mysql_real_escape_string($_POST[password])."'")
or die ("Error - Couldn't login user.");

$valid = mysql_num_rows($query); //counts the results in rows

if ($valid > 0) // found any rows matched the query? (valid login/account?)
{
$_SESSION[username] = $row[username];
echo "Welcome ".$_POST[username]."! You've been successfully logged in.";
//exit(); <- wouldn't do that ;) terminates the program
}
else // bad info.
{
echo "Error - Couldn't login user.<br /><br />
Please try again.";
exit();
}
}

?> 

Also added the mysql_real_escape_string function because you don't want to end up with all sort of SQL injections being executed. Never use userinput directly, plain as the user put it in... And you should put $_POST variables ( arrays ) between '". and ."' instead of ' and '. Same goes for when echoing it, you should NEVER put variables between double quotes and nor for arrays at all. This should work, let me know.

#12
laser212

laser212

    Newbie

  • Members
  • PipPip
  • 25 posts
thanks man but im not using that script any more i have a more secure and complicated one using account confirmation by email
but i have some trouble with that one