Here is my code. It is perfectly working on Local but not server. Need any library to work on server.

<?php
//include "../dbconnect/cnn_mysql.php";
//mysql_query("insert into admin (loginid, pass) values ('superuser', '".md5('mypassword123')."')");
if($_POST)
{
	include "../dbconnect/cnn_mysql.php";
	//$userid=mysql_real_escape_string($_POST["userid"]);
	//$pass=mysql_real_escape_string($_POST["pass"]);	
	
	$userid=secure_form_data($_POST["userid"]);
	$pass=md5(secure_form_data($_POST["pass"]));	
	
	$result=mysql_query("select * from admin where loginid='$userid'");
	
	if($result && mysql_num_rows($result)>0)
	{
		
		$row=mysql_fetch_array($result);
		
		$auserid = $row["loginid"];
		$apassword = $row["pass"];
		
		if($auserid == $userid && $apassword == $pass)
		{
		
		session_start();
		$_SESSION["adminid"]=$userid;
		header("location: main.php");
		exit();
		}
		else
		{
			$errors[]="1.1";
		}
		
	}
	else
	{
		$errors[]="1.1";
	}
	
	/*$userid=secure_form_data($_POST["userid"]);
	$pass=secure_form_data($_POST["pass"]);	
	
	$result=mysql_query("select * from admin where loginid='$userid' and pass='$pass'");
	
	if($result && mysql_num_rows($result)>0)
	{
		session_start();
		$_SESSION["adminid"]=$userid;
		header("location: main.php");
		exit();
		
	}
	else
	{
		$errors[]="1.1";
	}*/
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>KPO Jobs: Admin</title>
<link href="css/style.css" rel="stylesheet" type="text/css">

<script language="javascript">
function checkform(theform)
{
	var flds="";
	if(theform.userid.value=="")
		flds += "   *Login id\n";
	
	if(theform.pass.value=="")
		flds += "   *Password\n";	
	
	if(flds!="")
	{
		alert("The following fields can't be left blank\n"+flds);
		return false;
	}
	return true;
}
</script>
</head>
<body>
<div id="body_container">
<div id="head">
<img src="images/logo.jpg" class="logo" alt="KPO Jobs">
</div><!--head-->
<div id="main_content" class="main_content centeralgin">
<div id="for_height"></div>
&nbsp;
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" class='th_form width1' onsubmit="return checkform(this);" >
<fieldset>
<legend>Login</legend>
<?php 
include "module_error.php";
?>
<div class="form_row">
<label for="userid"><span>*</span>Login id:</label>
<input type="text" id="userid" name="userid" size="30">
</div>
<div class="form_row">
<label for="pass"><span>*</span>Password:</label>
<input type="password" id="pass" name="pass" size="30">
</div>
<div class="form_row">
<label >&nbsp;</label>
<input type="submit" id="login_bt" name="login_bt" value="Login">
</div>
<div class="formtip">Fields marked with <span>*</span> are compulsorry to fill.</div>
</fieldset>
</form>
<div class="clear"></div>
</div><!--main_content-->
<?php include "module_footer.php";?>
</div><!--body_container-->
</body>
</html>

Recommended Answers

All 5 Replies

It seems you are using a function secure_form_data() , did you included that in your online code? What it does? If you try to echo $pass which output you get?

Member Avatar for diafol

if I was a betting man, I'd bet it wasn't md5(). Check your connection details and the functions which you don't include here.

if I was a betting man, I'd bet it wasn't md5(). Check your connection details and the functions which you don't include here.

I included all the files.. Actually.. Its not entering into POST block.

Member Avatar for diafol

I wouldn't do it this way - $_POST is fickle, go specific, based on the login submit:

<input type="submit" id="login_bt" name="login_bt" value="Login">
if(isset($_POST['login_bt'])){
//whatever
}

Another thing, posting to the same page can cause problems with the back button and page refresh - you end up sending the data again. For this, use a formhandler page, ie send formdata to a different file then redirect back to formpage if you need to.

I included all the files.

No you didn't:

include "../dbconnect/cnn_mysql.php";
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.