binumathew Posted March 5, 2009 Share Posted March 5, 2009 <?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? Quote Link to comment https://forums.phpfreaks.com/topic/148083-solved-why-the-if-not-working/ Share on other sites More sharing options...
Maq Posted March 5, 2009 Share Posted March 5, 2009 You're using an assignment equals rather than a comparator. You need to make all your IF's like this: if($_POST["Type"]=='CA') Notice 2 equal signs. Quote Link to comment https://forums.phpfreaks.com/topic/148083-solved-why-the-if-not-working/#findComment-777271 Share on other sites More sharing options...
rhodesa Posted March 5, 2009 Share Posted March 5, 2009 p.s. - this is a double post....i just replied here too: http://www.phpfreaks.com/forums/index.php/topic,241675.new.html binumathew, this doesn't belong in this forum either. it should be in PHP. also, don't double post Quote Link to comment https://forums.phpfreaks.com/topic/148083-solved-why-the-if-not-working/#findComment-777277 Share on other sites More sharing options...
binumathew Posted March 5, 2009 Author Share Posted March 5, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/148083-solved-why-the-if-not-working/#findComment-777330 Share on other sites More sharing options...
rhodesa Posted March 5, 2009 Share Posted March 5, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/148083-solved-why-the-if-not-working/#findComment-777336 Share on other sites More sharing options...
Maq Posted March 5, 2009 Share Posted March 5, 2009 where did the other topic go? i posted the code there. well, anyways, here it is again: Yeah I saw that, I reported a double post and I guess it got deleted. Hopefully this works...! Quote Link to comment https://forums.phpfreaks.com/topic/148083-solved-why-the-if-not-working/#findComment-777337 Share on other sites More sharing options...
binumathew Posted March 5, 2009 Author Share Posted March 5, 2009 Still it not working,it shows a blank page Quote Link to comment https://forums.phpfreaks.com/topic/148083-solved-why-the-if-not-working/#findComment-777344 Share on other sites More sharing options...
rhodesa Posted March 5, 2009 Share Posted March 5, 2009 add this to the top of the script: ini_set ("display_errors", "1"); error_reporting(E_ALL); special thanks to Maq for having it in his sig Quote Link to comment https://forums.phpfreaks.com/topic/148083-solved-why-the-if-not-working/#findComment-777353 Share on other sites More sharing options...
Maq Posted March 5, 2009 Share Posted March 5, 2009 add this to the top of the script: ini_set ("display_errors", "1"); error_reporting(E_ALL); special thanks to Maq for having it in his sig Hehehe, that's why I keep it there Quote Link to comment https://forums.phpfreaks.com/topic/148083-solved-why-the-if-not-working/#findComment-777357 Share on other sites More sharing options...
binumathew Posted March 5, 2009 Author Share Posted March 5, 2009 Till I add the code it not working can i post my index.php file and LoginCheck.php file?? Quote Link to comment https://forums.phpfreaks.com/topic/148083-solved-why-the-if-not-working/#findComment-777359 Share on other sites More sharing options...
binumathew Posted March 5, 2009 Author Share Posted March 5, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/148083-solved-why-the-if-not-working/#findComment-777363 Share on other sites More sharing options...
binumathew Posted March 5, 2009 Author Share Posted March 5, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/148083-solved-why-the-if-not-working/#findComment-777366 Share on other sites More sharing options...
Maq Posted March 5, 2009 Share Posted March 5, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/148083-solved-why-the-if-not-working/#findComment-777371 Share on other sites More sharing options...
binumathew Posted March 5, 2009 Author Share Posted March 5, 2009 Its Now Shows a Run time error it displaying the FORM even if the the USERID And PASSWORD IS WRONG Quote Link to comment https://forums.phpfreaks.com/topic/148083-solved-why-the-if-not-working/#findComment-777381 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.