Jump to content

Recommended Posts

<?php

$con = mysql_connect("localhost","root","erd");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("erd", $con);

 

if($_POST["Type"]='CA')

{

$type="College Admin";

}

if($_POST["Type"]='stud')

{

$type="Student";

}

$query="SELECT * FROM scmanager.user_login_details where userID= '".$_POST["userid"]."' AND password='".$_POST["psw"]."' and role='".$type."'";

 

$result=mysql_query($query) or die('error');

$numrows = mysql_num_rows($result);

 

if(!numrows)

{

if($_POST["Type"]='CA')

{

echo "<center>";

echo "<div class='main'>";

echo "<div class='box'>";

echo "Congrates! You got Loged In";

echo "<br><br>";

echo "<form action='ca/CAdminHome.php' method='post' name='myform'>";

echo "<input type='hidden' name='userID2' value='".$_POST["userid"]."'>";

echo "<input type='hidden' name='type2' value='".$_POST["Type"]."'>";

echo "<div class='spacer'><a href='#' onClick='document.myform.submit();' class='green'>Enter</a></div>";

echo "</form>";

echo "</div>";

echo "</div>";

echo "</div>";

echo"</center>";

echo "</body>";

}

 

elseif($_POST["Type"]='stud')

{

 

echo "<center>";

echo "<div class='main'>";

echo "<div class='box'>";

echo "Congrates! You got Loged In";

echo "<br><br>";

echo "<form action='Student/CAdminHome.php' method='post' name='myform1'>";

echo "<input type='hidden' name='userID2' value='".$_POST["userid"]."'>";

echo "<input type='hidden' name='type2' value='".$_POST["Type"]."'>";

echo "<div class='spacer'><a href='#' onClick='document.myform1.submit();' class='green'>Enter</a></div>";

echo "</form>";

echo "</div>";

echo "</div>";

echo "</div>";

echo"</center>";

echo "</body>";

}

else

{

Header("Location: http://127.0.0.1:8080/scmanager/relogin.php");

exit;

}

}

mysql_close($con);

?>

 

I think there is an Error in the "if" code can u say what is that?

Link to comment
https://forums.phpfreaks.com/topic/148083-solved-why-the-if-not-working/
Share on other sites

Sir,

i Change the code as You Said Then also its not working

 

<?php

$con = mysql_connect("localhost","root","javabeanc");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("scmanager", $con);

 

if($_POST["Type"]='CA')

{

$type="College Admin";

}

if($_POST["Type"]='stud')

{

$type="Student";

}

$query="SELECT * FROM scmanager.user_login_details where userID= '".$_POST["userid"]."' AND password='".$_POST["psw"]."' and role='".$type."'";

 

$result=mysql_query($query) or die('error');

$numrows = mysql_num_rows($result);

 

if(!$numrows)

{

if($_POST["Type"]=='CA')

{

echo "<center>";

echo "<div class='main'>";

echo "<div class='box'>";

echo "Congrates! You got Loged In";

echo "<br><br>";

echo "<form action='ca/CAdminHome.php' method='post' name='myform'>";

echo "<input type='hidden' name='userID2' value='".$_POST["userid"]."'>";

echo "<input type='hidden' name='type2' value='".$_POST["Type"]."'>";

echo "<div class='spacer'><a href='#' onClick='document.myform.submit();' class='green'>Enter</a></div>";

echo "</form>";

echo "</div>";

echo "</div>";

echo "</div>";

echo"</center>";

echo "</body>";

}

 

elseif($_POST["Type"]=='stud')

{

 

echo "<center>";

echo "<div class='main'>";

echo "<div class='box'>";

echo "Congrates! You got Loged In";

echo "<br><br>";

echo "<form action='Student/CAdminHome.php' method='post' name='myform1'>";

echo "<input type='hidden' name='userID2' value='".$_POST["userid"]."'>";

echo "<input type='hidden' name='type2' value='".$_POST["Type"]."'>";

echo "<div class='spacer'><a href='#' onClick='document.myform1.submit();' class='green'>Enter</a></div>";

echo "</form>";

echo "</div>";

echo "</div>";

echo "</div>";

echo"</center>";

echo "</body>";

}

else

{

Header("Location: http://127.0.0.1:8080/scmanager/relogin.php");

exit;

}

}

mysql_close($con);

?>

 

<!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>Welcome to ScManager Ver 1.0  | Developed by iTMarkerZ Technologies</title>

<style type="text/css">

body{ font-family:"Lucida Sans Unicode", "Lucida Grande", Verdana, Arial, Helvetica, sans-serif;

font-size:12px;

color:#000000;

}

a{color:#0033CC;}

h1, h2, p, form{

border:0px;

margin:0px;

padding:0px;

}

 

input{ font-family:"Lucida Sans Unicode", "Lucida Grande", Verdana, Arial, Helvetica, sans-serif;

font-size:12px;

}

h2{ color:#666666;

margin-bottom:20px;

font-size:16px;

}

 

div.main{

margin:30px auto;

width:340px;

}

 

div.box{

border:solid 1px #c6cfe1;

background:#dfe4ee;

padding:10px;

color:#333333;

margin-bottom:20px;

}

div.box h1 {

font-size:14px;

color:#000000;

padding-bottom:4px;

}

div.box p{padding-bottom:14px;}

 

div.box input .input-text{

border:1px solid #3b6e22;

color:#666666;

width:180px;

}

 

div.box label{

display:block;

margin-bottom:10px;

color:#555555;

}

 

div.box label span{

display:block;

float:left;

padding-right:6px;

width:70px;

text-align:right;

font-weight:bold;

}

.spacer{margin-left:80px;

margin-bottom:10px;

font-size:11px;

color:#555555;

}

.green{

background:url(img/green.gif);

padding:0px 6px;

border:1px solid #3b6e22;

height:24px;

line-height:24px;

color:#FFFFFF;

font-size:12px;

margin-right:10px;

display:inline-block;

text-decoration:none;

}

<body>

 

 

where did the other topic go? i posted the code there. well, anyways, here it is again:

 

you STILL aren't using [ code ][ /code ] tags. STOP copying/pasting large blocks of code without the tags. before you paste, click the button in the toolbar with the # on it. it will add the tags, then you paste in between them.

 

second, Maq gave you your answer, but you did not follow it completely. when comparing two things, you need to use a double equals:

<?php
$con = mysql_connect("localhost","root","javabeanc");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("scmanager", $con);

if($_POST["Type"]=='CA') //Double equals needed here
{
$type="College Admin";
}
if($_POST["Type"]=='stud') //Double equals needed here
{
$type="Student";
}
//Added mysql_real_escape_string() the following line to stop SQL injection
$query="SELECT * FROM scmanager.user_login_details where userID= '".mysql_real_escape_string($_POST["userid"])."' AND password='".mysql_real_escape_string($_POST["psw"])."' and role='".$type."'";

$result=mysql_query($query) or die('error');
$numrows = mysql_num_rows($result);

if(!$numrows)
{
if($_POST["Type"]=='CA')
{
echo "<center>";
echo "<div class='main'>";
echo "<div class='box'>";
echo "Congrates! You got Loged In";
echo "<br><br>";
echo "<form action='ca/CAdminHome.php' method='post' name='myform'>";
echo "<input type='hidden' name='userID2' value='".$_POST["userid"]."'>";
echo "<input type='hidden' name='type2' value='".$_POST["Type"]."'>";
echo "<div class='spacer'><a href='#' onClick='document.myform.submit();' class='green'>Enter</a></div>";
echo "</form>";
echo "</div>";
echo "</div>";
echo "</div>";
echo"</center>";
echo "</body>";
}

elseif($_POST["Type"]=='stud')
{

echo "<center>";
echo "<div class='main'>";
echo "<div class='box'>";
echo "Congrates! You got Loged In";
echo "<br><br>";
echo "<form action='Student/CAdminHome.php' method='post' name='myform1'>";
echo "<input type='hidden' name='userID2' value='".$_POST["userid"]."'>";
echo "<input type='hidden' name='type2' value='".$_POST["Type"]."'>";
echo "<div class='spacer'><a href='#' onClick='document.myform1.submit();' class='green'>Enter</a></div>";
echo "</form>";
echo "</div>";
echo "</div>";
echo "</div>";
echo"</center>";
echo "</body>";
}
else
{
Header("Location: http://127.0.0.1:8080/scmanager/relogin.php");
exit;
}
}
mysql_close($con);
?>

<!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>Welcome to ScManager Ver 1.0  | Developed by iTMarkerZ Technologies</title>
<style type="text/css">
body{   font-family:"Lucida Sans Unicode", "Lucida Grande", Verdana, Arial, Helvetica, sans-serif;
   font-size:12px;
   color:#000000;
}
a{color:#0033CC;}
h1, h2, p, form{
   border:0px;
   margin:0px;
   padding:0px;
}

input{   font-family:"Lucida Sans Unicode", "Lucida Grande", Verdana, Arial, Helvetica, sans-serif;
   font-size:12px;
}
h2{   color:#666666;
   margin-bottom:20px;
   font-size:16px;
}

div.main{
   margin:30px auto;
   width:340px;
   }

div.box{
   border:solid 1px #c6cfe1;
   background:#dfe4ee;
   padding:10px;
   color:#333333;
   margin-bottom:20px;
}
div.box h1 {
   font-size:14px;
   color:#000000;
   padding-bottom:4px;
}
div.box p{padding-bottom:14px;}

div.box input .input-text{
   border:1px solid #3b6e22;
   color:#666666;
   width:180px;
}

div.box label{
   display:block;
   margin-bottom:10px;
   color:#555555;
}

div.box label span{
   display:block;
   float:left;
   padding-right:6px;
   width:70px;
   text-align:right;
   font-weight:bold;
}
.spacer{margin-left:80px;
   margin-bottom:10px;
   font-size:11px;
   color:#555555;
}
.green{
   background:url(img/green.gif);
   padding:0px 6px;
   border:1px solid #3b6e22;
   height:24px;
   line-height:24px;
   color:#FFFFFF;
   font-size:12px;
   margin-right:10px;
   display:inline-block;
   text-decoration:none;
}
<body>

Index.php

 


<!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>Welcome to ScManager Ver 1.0  | Developed by iTMarkerZ Technologies</title>

<style type="text/css">
body{	font-family:"Lucida Sans Unicode", "Lucida Grande", Verdana, Arial, Helvetica, sans-serif; 
font-size:12px; 
color:#000000;
}
a{color:#0033CC;}
h1, h2, p, form{
border:0px; 
margin:0px; 
padding:0px;
}

input{	font-family:"Lucida Sans Unicode", "Lucida Grande", Verdana, Arial, Helvetica, sans-serif; 
font-size:12px;
}
h2{	color:#666666; 
margin-bottom:20px;
font-size:16px;
}

div.main{
margin:30px auto; 
width:340px;
}

div.box{
border:solid 1px #c6cfe1;
background:#dfe4ee;
padding:10px;
color:#333333;
margin-bottom:20px;
}
div.box h1 {
font-size:14px;
color:#000000;
padding-bottom:4px;
}
div.box p{padding-bottom:14px;}

div.box input .input-text{
border:1px solid #3b6e22;
color:#666666;
width:180px;
}

div.box label{
display:block;
margin-bottom:10px;
color:#555555;
}

div.box label span{
display:block;
float:left;
padding-right:6px;
width:70px;
text-align:right;
font-weight:bold;
}
.spacer{margin-left:80px; 
margin-bottom:10px;
font-size:11px;
color:#555555;
}
.green{
background:url(img/green.gif);
padding:0px 6px;
border:1px solid #3b6e22;
height:24px; 
line-height:24px;
color:#FFFFFF;
font-size:12px;
margin-right:10px;
display:inline-block;
text-decoration:none;
}

</style>

</head>

<body>
<div class="main">
<h1>ScManager Ver 1.0</h1>
<h2>iTMarkerZ Technologies</h2>
For more info visit: <a href="http://itmarkerz.co.in">iTMarkerZ Technologies</a>
<br/><br/>

<div class="box">
<h1>Sign in</h1>

<form action="checklogin.php" method="post" name="myform">
<label><span>User ID</span>
<input type="text" name="userid" id="userid" class="input-text"/>
</label>
<label><span>Password</span>
<input type="password" name="psw" id="psw" class="input-text"/>
</label>
<label><span>Type</span>
<select name="Type">
  <option value="CA">College Admin</option>
  <option value="HOD">Head Of Department</option>
  <option value="SIC">Staff In Charge</option>
  <option value="DO">Data Entry Operator</option>
  <option value="PAR">Parent</option>
<option value="stud">Studnet</option>

</select>
</label>

</form>
<div class="spacer"><a href="#" onClick="document.myform.submit();" class="green">Sign in</a></div>
<div class="spacer">
Lost your data? <a href="lostpassword.php">Get your password</a><br/>
</div>
</div>



</div>
</body>
</html>


Check Login

<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);
$con = mysql_connect("localhost","root","javabeanc");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("scmanager", $con);

if($_POST["Type"]=='CA') //Double equals needed here
{
$type="College Admin";
}
if($_POST["Type"]=='stud') //Double equals needed here
{
$type="Student";
}
//Added mysql_real_escape_string() the following line to stop SQL injection
$query="SELECT * FROM scmanager.user_login_details where userID= '".mysql_real_escape_string($_POST["userid"])."' AND password='".mysql_real_escape_string($_POST["psw"])."' and role='".$type."'";

$result=mysql_query($query) or die('error');
$numrows = mysql_num_rows($result);

if(!$numrows)
{
if($_POST["Type"]=='CA')
{
echo "<center>";
echo "<div class='main'>";
echo "<div class='box'>";
echo "Congrates! You got Loged In";
echo "<br><br>";
echo "<form action='ca/CAdminHome.php' method='post' name='myform'>";
echo "<input type='hidden' name='userID2' value='".$_POST["userid"]."'>";
echo "<input type='hidden' name='type2' value='".$_POST["Type"]."'>";
echo "<div class='spacer'><a href='#' onClick='document.myform.submit();' class='green'>Enter</a></div>";
echo "</form>";
echo "</div>";
echo "</div>";
echo "</div>";
echo"</center>";
echo "</body>";
}

elseif($_POST["Type"]=='stud')
{

echo "<center>";
echo "<div class='main'>";
echo "<div class='box'>";
echo "Congrates! You got Loged In";
echo "<br><br>";
echo "<form action='Student/CAdminHome.php' method='post' name='myform1'>";
echo "<input type='hidden' name='userID2' value='".$_POST["userid"]."'>";
echo "<input type='hidden' name='type2' value='".$_POST["Type"]."'>";
echo "<div class='spacer'><a href='#' onClick='document.myform1.submit();' class='green'>Enter</a></div>";
echo "</form>";
echo "</div>";
echo "</div>";
echo "</div>";
echo"</center>";
echo "</body>";
}
else
{
Header("Location: http://127.0.0.1:8080/scmanager/relogin.php");
exit;
}
}
mysql_close($con);
?>

<!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>Welcome to ScManager Ver 1.0  | Developed by iTMarkerZ Technologies</title>
<style type="text/css">
body{   font-family:"Lucida Sans Unicode", "Lucida Grande", Verdana, Arial, Helvetica, sans-serif;
   font-size:12px;
   color:#000000;
}
a{color:#0033CC;}
h1, h2, p, form{
   border:0px;
   margin:0px;
   padding:0px;
}

input{   font-family:"Lucida Sans Unicode", "Lucida Grande", Verdana, Arial, Helvetica, sans-serif;
   font-size:12px;
}
h2{   color:#666666;
   margin-bottom:20px;
   font-size:16px;
}

div.main{
   margin:30px auto;
   width:340px;
   }

div.box{
   border:solid 1px #c6cfe1;
   background:#dfe4ee;
   padding:10px;
   color:#333333;
   margin-bottom:20px;
}
div.box h1 {
   font-size:14px;
   color:#000000;
   padding-bottom:4px;
}
div.box p{padding-bottom:14px;}

div.box input .input-text{
   border:1px solid #3b6e22;
   color:#666666;
   width:180px;
}

div.box label{
   display:block;
   margin-bottom:10px;
   color:#555555;
}

div.box label span{
   display:block;
   float:left;
   padding-right:6px;
   width:70px;
   text-align:right;
   font-weight:bold;
}
.spacer{margin-left:80px;
   margin-bottom:10px;
   font-size:11px;
   color:#555555;
}
.green{
   background:url(img/green.gif);
   padding:0px 6px;
   border:1px solid #3b6e22;
   height:24px;
   line-height:24px;
   color:#FFFFFF;
   font-size:12px;
   margin-right:10px;
   display:inline-block;
   text-decoration:none;
}
<body>

No errors, no output?

 

Can you add an echo here to see if you're passing anything through?

 

mysql_select_db("scmanager", $con);

echo "****" . $_POST['Type'] . "****";   //add this line here

if($_POST["Type"]=='CA') //Double equals needed here

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.