<?php
// connection to MySQL server
mysql_connect('localhost','root','root');
mysql_select_db('administration');

// *** Validate request to login to this site.
//session_start();

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($accesscheck)) {
  $GLOBALS['PrevUrl'] = $accesscheck;
  session_register('PrevUrl');
}

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  //$MM_fldUserAuthorization = "level_usr";
  $MM_redirectLoginSuccess = "validated.php";
  $MM_redirectLoginFailed = "index.html";
  $MM_redirecttoReferrer = true;
  //mysql_select_db($database_connBlog, $connBlog);
  mysql_select_db($database, $administration);
      
  $LoginRS__query=sprintf("SELECT username, password FROM adminprofile WHERE username='%s' AND password='%s'",
  get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); 
  $LoginRS = mysql_query($LoginRS__query, $adminprofile) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
    
   // $loginStrGroup  = mysql_result($LoginRS,0,'level_usr');
    
    //declare two session variables and assign them
   // $GLOBALS['MM_Username'] = $loginUsername;
    //$GLOBALS['MM_UserGroup'] = $loginStrGroup;          

    //register the session variables
    //session_register("MM_Username");
    //session_register("MM_UserGroup");

    if (isset($_SESSION['PrevUrl']) && true) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];    
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>

errors:
1.Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in D:\xampp\htdocs\cycle\validate.php on line 34

2.Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in D:\xampp\htdocs\cycle\validate.php on line 38


Please help as I couldn't make the code to check my username and password from the login page and validate it with the information stored in the database.

On line 23, mysql_select_db($database, $administration); What are you trying to do ?
If administration is the database name, you should give, mysql_select_db('administration'); Read more on mysql_select_db here.

Thank you nav33. I did not noticed it. But even though I've amend it, the 2nd error was still there. Kindly help. $adminprofile is the table inside database 'administration'

You dont need $adminprofile. mysql_query takes 2 parameters. 1. The query and 2. The connection resource. The second one is optional.

yes i managed to identify the errors, but now the problem is at line "44". It doesn't redirect me? any of the syntaxes wrong? I'm really sorry if I'm asking too much. I'm new to this language.

The syntax isnt wrong. Print whats in $MM_redirectLoginSuccess and $MM_redirectLoginFailed. Header function fails if you are outputting ANYTHING before calling a header function.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title>Cycle Tracks Portal - Validation Page</title>
		<style type="text/css" media="all">@import "images/style.css";
</style>
	<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="rss/" />
</head>

<body>
<?php
// connection to MySQL server
mysql_connect('localhost','root','root');
mysql_select_db('administration');

// *** Validate request to login to this site.
//session_start();

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  $MM_redirectLoginSuccess = "validate.php";
  $MM_redirectLoginFailed = "index.html;
  $MM_redirecttoReferrer = true;
  mysql_select_db('administration');
      
  $LoginRS__query=sprintf("SELECT username, password FROM adminprofile WHERE username='%s' AND password='%s'",
  get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); 
  $LoginRS = mysql_query($LoginRS__query) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
    
    header("Location: " . $MM_redirectLoginSuccess );
	}
  else {
    header("Location: ". $MM_redirectLoginFailed );
}
?>

</body>
</html>

This my new set of codes. now the error at line "28".It says that,

"Parse error: syntax error, unexpected T_STRING in D:\xampp\htdocs\cycle\validate.php on line 28"

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title>Cycle Tracks Portal - Validation Page</title>
		<style type="text/css" media="all">@import "images/style.css";
</style>
	<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="rss/" />
</head>

<body>
<?php
// connection to MySQL server
mysql_connect('localhost','root','root');
mysql_select_db('administration');

// *** Validate request to login to this site.
//session_start();

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  $MM_redirectLoginSuccess = "validate.php";
  $MM_redirectLoginFailed = "index.html";
  $MM_redirecttoReferrer = true;
  mysql_select_db('administration');
      
  $LoginRS__query=sprintf("SELECT username, password FROM adminprofile WHERE username='%s' AND password='%s'",
  get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); 
  $LoginRS = mysql_query($LoginRS__query) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
    
    header("Location: " . $MM_redirectLoginSuccess );
	}
  else {
    header("Location: ". $MM_redirectLoginFailed );
}
?>

</body>
</html>

There was a missing ". :)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title>Cycle Tracks Portal - Validation Page</title>
		<style type="text/css" media="all">@import "images/style.css";
</style>
	<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="rss/" />
</head>

<body>
<?php
// connection to MySQL server
mysql_connect('localhost','root','root');
mysql_select_db('administration');

// *** Validate request to login to this site.
//session_start();

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  $MM_redirectLoginSuccess = "validate.php";
  $MM_redirectLoginFailed = "index.html;
  $MM_redirecttoReferrer = true;
  mysql_select_db('administration');
      
  $LoginRS__query=sprintf("SELECT username, password FROM adminprofile WHERE username='%s' AND password='%s'");
  get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); 
  $LoginRS = mysql_query($LoginRS__query) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
    
    header("Location: " . $MM_redirectLoginSuccess );
	}
  else {
    header("Location: ". $MM_redirectLoginFailed );
}
?>

</body>
</html>

Sorry it was a paste mistake. The previous error was still there even though the code has been corrected. pls help.

line 24. $MM_redirectLoginFailed = "index.html; <<< you haven't closed it.
It should have been
$MM_redirectLoginFailed = "index.html";
Use the code that I have posted in previous post. I guess it will work. Your new modified code has a different select query !

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title>Cycle Tracks Portal - Validation Page</title>
		<style type="text/css" media="all">@import "images/style.css";
</style>
	<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="rss/" />
</head>

<body>
<?php
// connection to MySQL server
mysql_connect('localhost','root','root');
mysql_select_db('administration');

// *** Validate request to login to this site.
//session_start();

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  $MM_redirectLoginSuccess = "validate.php";
  $MM_redirectLoginFailed = "index.html";
  $MM_redirecttoReferrer = true;
  mysql_select_db('administration');
      
  $LoginRS__query=sprintf("SELECT username, password FROM adminprofile WHERE username='%s' AND password='%s'"
  get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); 
  $LoginRS = mysql_query($LoginRS__query) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
    
    header("Location: " . $MM_redirectLoginSuccess );
	}
  else {
    header("Location: ". $MM_redirectLoginFailed );
}
?>

</body>
</html>

Yet it says that'
"Parse error: syntax error, unexpected T_STRING in D:\xampp\htdocs\cycle\validate.php on line 29"


Thanks for your continuing support!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title>Cycle Tracks Portal - Validation Page</title>
		<style type="text/css" media="all">@import "images/style.css";
</style>
	<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="rss/" />
</head>

<body>
<?php
// connection to MySQL server
mysql_connect('localhost','root','root');
mysql_select_db('administration');

// *** Validate request to login to this site.
//session_start();

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  $MM_redirectLoginSuccess = "validate.php";
  $MM_redirectLoginFailed = "index.html";
  $MM_redirecttoReferrer = true;
  mysql_select_db('administration');
      
  $LoginRS__query=sprintf("SELECT username, password FROM adminprofile WHERE username='%s' AND password='%s'",
  get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); 
  $LoginRS = mysql_query($LoginRS__query) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
    
    header("Location: " . $MM_redirectLoginSuccess );
	}
  else {
    header("Location: ". $MM_redirectLoginFailed );
}
?>

</body>
</html>

How come you keep missing one thing or the other :S ! Missing , this time. If this doesn't work, you can try this. It will surely work.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title>Cycle Tracks Portal - Validation Page</title>
		<style type="text/css" media="all">@import "images/style.css";
</style>
	<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="rss/" />
</head>

<body>
<?php
// connection to MySQL server
mysql_connect('localhost','root','root');
mysql_select_db('administration');

// *** Validate request to login to this site.
//session_start();

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  $MM_redirectLoginSuccess = "validate.php";
  $MM_redirectLoginFailed = "index.html";
  $MM_redirecttoReferrer = true;
  mysql_select_db('administration');

  $loginUsername=get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername);
  $password=get_magic_quotes_gpc() ? $password : addslashes($password);  
  $LoginRS__query="SELECT username, password FROM adminprofile WHERE username='$loginUsername' AND password='$password'";
  
  $LoginRS = mysql_query($LoginRS__query) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
    
    header("Location: " . $MM_redirectLoginSuccess );
	}
  else {
    header("Location: ". $MM_redirectLoginFailed );
}
?>

</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title>Cycle Tracks Portal - Validation Page</title>
		<style type="text/css" media="all">@import "images/style.css";
</style>
	<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="rss/" />
</head>

<body>
<?php
// connection to MySQL server
mysql_connect('localhost','root','root');
mysql_select_db('administration');

// *** Validate request to login to this site.
//session_start();

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $loginPassword=$_POST['password'];
  $MM_redirectLoginSuccess = "validate.php";
  $MM_redirectLoginFailed = "index.html";
  $MM_redirecttoReferrer = true;
  mysql_select_db('administration');
      
  $loginUsername = get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername);
  $password = get_magic_quotes_gpc() ? $password : addslashes($password);
  $LoginRS__query = "SELECT username, password FROM adminprofile WHERE username='$loginUsername' AND password='$loginPassword'";
  
  $LoginRS = mysql_query($LoginRS__query) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
    
    header("Location: " . $MM_redirectLoginSuccess );
	}
  else {
    header("Location: ". $MM_redirectLoginFailed );
}
?>

</body>
</html>

Thanks for your help. Now it says that,
"Parse error: syntax error, unexpected $end in D:\xampp\htdocs\cycle\validate.php on line 30"

I hope that you will help till the end to solve it ........ it is request, not order. actually what I'm trying to is, I've already created a database called
administration and inside it a table called adminprofile. When the admin of this webpage login with his username and password, the code should connect to the database and the table to check whether the inputed username and password matches with the one in the table. This is the scenario. Thx a lot for all your help. pls reply.

no problem. Put a } before line 40. That will probably solve it.

thank you very much. I will reply u in 9 - 10 hours time. I need to sleep n relax my mind. I was a nice meeting you online. Proud to see a Indian in the forum. Thx a lot. I hope you will check this thread again.

you are welcome! and ofcourse, i ll check this thread. I ll be here almost 17 hrs a day. lol.. I hope your code worked! Just in case you didn't find where to put } brace.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title>Cycle Tracks Portal - Validation Page</title>
		<style type="text/css" media="all">@import "images/style.css";
</style>
	<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="rss/" />
</head>

<body>
<?php
// connection to MySQL server
mysql_connect('localhost','root','root');
mysql_select_db('administration');

// *** Validate request to login to this site.
//session_start();

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $loginPassword=$_POST['password'];
  $MM_redirectLoginSuccess = "validate.php";
  $MM_redirectLoginFailed = "index.html";
  $MM_redirecttoReferrer = true;
  mysql_select_db('administration');
      
  $loginUsername = get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername);
  $password = get_magic_quotes_gpc() ? $password : addslashes($password);
  $LoginRS__query = "SELECT username, password FROM adminprofile WHERE username='$loginUsername' AND password='$loginPassword'";
  
  $LoginRS = mysql_query($LoginRS__query) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
    
    header("Location: " . $MM_redirectLoginSuccess );
	}
  else {
    header("Location: ". $MM_redirectLoginFailed );
}
}
?>

</body>
</html>

:)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title>Cycle Tracks Portal - Validation Page</title>
		<style type="text/css" media="all">@import "images/style.css";
</style>
	<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="rss/" />
</head>

<body>
<?php
// connection to MySQL server
mysql_connect('localhost','root','root');
mysql_select_db('administration');

// *** Validate request to login to this site.
//session_start();

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $loginPassword=$_POST['password'];
  $MM_redirectLoginSuccess = "validated.php";
  $MM_redirectLoginFailed = "index.html";
  $MM_redirecttoReferrer = true;
  mysql_select_db('administration');
      
  $loginUsername = get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername);
  $password = get_magic_quotes_gpc() ? $password : addslashes($password);
  $LoginRS__query = "SELECT username, password FROM adminprofile WHERE username='$loginUsername' AND password='$loginPassword'";
  
  $LoginRS = mysql_query($LoginRS__query) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
    
    header("Location: " . $MM_redirectLoginSuccess );
	}
  else {
    header("Location: ". $MM_redirectLoginFailed );
}
}
?>

</body>
</html>

Thank you for your support. Now a new problem with the code above(same as your code before),

"Warning: Cannot modify header information - headers already sent by (output started at D:\xampp\htdocs\cycle\validate.php:6) in D:\xampp\htdocs\cycle\validate.php on line 36"

hmm.. Try this.

<?php 
ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title>Cycle Tracks Portal - Validation Page</title>
		<style type="text/css" media="all">@import "images/style.css";
</style>
	<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="rss/" />
</head>

<body>
<?php
// connection to MySQL server
mysql_connect('localhost','root','root');
mysql_select_db('administration');

// *** Validate request to login to this site.
//session_start();

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $loginPassword=$_POST['password'];
  $MM_redirectLoginSuccess = "validated.php";
  $MM_redirectLoginFailed = "index.html";
  $MM_redirecttoReferrer = true;
  mysql_select_db('administration');
      
  $loginUsername = get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername);
  $password = get_magic_quotes_gpc() ? $password : addslashes($password);
  $LoginRS__query = "SELECT username, password FROM adminprofile WHERE username='$loginUsername' AND password='$loginPassword'";
  
  $LoginRS = mysql_query($LoginRS__query) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
    
    header("Location: " . $MM_redirectLoginSuccess );
	}
  else {
    header("Location: ". $MM_redirectLoginFailed );
}
}
?>

</body>
</html>
<?php 
ob_end_flush(); 
?>

Now,

"
Warning: Cannot modify header information - headers already sent by (output started at D:\xampp\htdocs\cycle\validate.php:1) in D:\xampp\htdocs\cycle\validate.php on line 39"

I wonder why you are still getting header already sent error even after using ob_start and ob_end_flush. But the reason why you get this error is, you shouldn't output anything(not even html tags) to the browser before calling a header function. Instead of header function, use,

echo "<script type='text/javascript'>location.href='$MM_redirectLoginSuccess';</script>";

I guess that will solve the problem.

Problem solved! hoorey....... thank you my friend, u have helped me alot. other then this forum, do u have yahoo or msn messenger to chat, thats if only u want to chat. I can frequently ask u some php questions. up to you and thanks a lot!!!!! my email is >email snipped<. thx. Will post here if any future problems and hope u'll be there to give some hands.

You are welcome ! I am glad your problem was solved. If you have any questions/problems, you can post it here. That will help those who might be facing the same problem :)

Cheers,
Naveen

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.