Cannot run my if statement

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 1183 Views - Last Post: 07 July 2010 - 06:53 PM Rate Topic: -----

#16 Johnson-php  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 76
  • Joined: 14-November 09

Re: Cannot run my if statement

Posted 07 July 2010 - 06:25 PM

try changing this " <select name="department">
" to this " <select name="Department">"
Was This Post Helpful? 0
  • +
  • -

#17 Rhoda Rose  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 93
  • Joined: 21-June 10

Re: Cannot run my if statement

Posted 07 July 2010 - 06:34 PM

I do what you have suggest i change the <select name="department">
to <select name="Department"> but the result is still the same when i choose accounting department and i click the submit button the result is error: There is no department by that name
Was This Post Helpful? 0
  • +
  • -

#18 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5313
  • View blog
  • Posts: 27,216
  • Joined: 10-May 07

Re: Cannot run my if statement

Posted 07 July 2010 - 06:40 PM

Validate your varibles. Do you know $result contains a value? No. You can't be certain that anything was selected because you never checked it.

$result=mysql_query($sql);  

  
    if($row['Department']=='Accounting')



Validate that SQL!

$result=mysql_query($sql);  

if(!$result) die("SQL Failed<br>".$sql);
  
    if($row['Department']=='Accounting')




Also.. what I would do.. instead of all of this :

  
    if($row['Department']=='Accounting')
		{
			header('location:accounting.php');
		}
	if($row['Department']=='Engineering')
		{
			header('location:engineering.php');
		}
    if($row['Department']=='Finishing_Goods')
		{
			header('location:finishing_goods.php');
		}
    if($row['Department']=='HRAD')
		{
			header('location:HRAD.php');
		}
    if($row['Department']=='MIS')
		{
			header('location:MIS.php');
		}
    if($row['Department']=='Packaging_and_Design')
		{
			header('location:packaging_design.php');
		}
    if($row['Department']=='Production')
		{
			header('location:production.php');
		}
    if($row['Department']=='Purchasing_Logistic')
		{
			header('location:purchasing_logistic.php');
		}
    if($row['Department']=='QA_and_Technical')
		{
			header('location:QA_technical.php');
		}
    if($row['Department']=='Supply_Chain')
		{
			header('location:supply_chain.php');
		}
	
     // do your redirect stuff here.  



I would make another column in your sql, make it a string, & have it contain the 'pretty' name. Such as QA_technical, supply_chain, & so on. Then you can get rid of all that php garbage code & just shoot to what was selected.

$sql="SELECT Department,PrettyDepartment FROM tbllogin WHERE Department = $department";
$result=mysql_query($sql);  

if(!$result) die("SQL Failed<br>".$sql);
if(!empty($row['PrettyDepartment'] {
  $url="location".$row['PrettyDepartment']:
  header($url);
}


Was This Post Helpful? 1
  • +
  • -

#19 Rhoda Rose  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 93
  • Joined: 21-June 10

Re: Cannot run my if statement

Posted 07 July 2010 - 06:42 PM

I revised my code

this is my code for the form.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=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
#Layer1 {
	position:absolute;
	width:200px;
	height:115px;
	z-index:1;
	left: 21px;
	top: 228px;
}
#Layer2 {
	position:absolute;
	width:267px;
	height:115px;
	z-index:1;
	left: 425px;
	top: 238px;
}
#Layer3 {
	position:absolute;
	width:329px;
	height:89px;
	z-index:1;
	left: 478px;
	top: 298px;
}
#Layer4 {
	position:absolute;
	width:197px;
	height:34px;
	z-index:2;
	left: 15px;
	top: 35px;
}
.style1 {
	font-size: 12px;
	font-family: Verdana, Arial, Helvetica, sans-serif;
}
#Layer5 {
	position:absolute;
	width:376px;
	height:83px;
	z-index:2;
	left: 361px;
	top: 329px;
}
#Layer6 {
	position:absolute;
	width:327px;
	height:36px;
	z-index:3;
	left: 377px;
	top: 341px;
}
#Layer7 {
	position:absolute;
	width:99px;
	height:56px;
	z-index:4;
	left: 567px;
	top: 395px;
}
#Layer8 {
	position:absolute;
	width:66px;
	height:35px;
	z-index:5;
	left: 393px;
	top: 355px;
}
#Layer9 {
	position:absolute;
	width:187px;
	height:36px;
	z-index:6;
	left: 112px;
	top: 131px;
}
#Layer10 {
	position:absolute;
	width:298px;
	height:65px;
	z-index:7;
	left: 475px;
	top: 262px;
}
#Layer11 {
	position:absolute;
	width:122px;
	height:57px;
	z-index:8;
	left: 364px;
	top: 315px;
}
#Layer12 {
	position:absolute;
	width:182px;
	height:31px;
	z-index:9;
	left: 489px;
	top: 271px;
}
#Layer13 {
	position:absolute;
	width:80px;
	height:41px;
	z-index:10;
	left: 547px;
	top: 334px;
}
#Layer14 {
	position:absolute;
	width:58px;
	height:26px;
	z-index:11;
	left: 555px;
	top: 340px;
}
-->
</style>
</head>
<body background="bgroundv03.png" bgproperties="fixed">
<form id="form1" name="form1" method="post" action="loginv05.php">
 
  <div id="Layer12">
 
    <select name="department">
      <option>Choose your Department</option>
      <option value="Accounting">Accounting</option>
      <option value="Engineering">Engineering</option>
      <option value="Finishing_Goods">Finishing Goods</option>
      <option value="HRAD">HRAD</option>
      <option value="MIS">MIS</option>
      <option value="Packaging_and_Design">Packaging and Design</option>
      <option value="Production">Production</option>
      <option value="Purchasing_Logistic">Purchasing and Logistics</option>
      <option value="QA_and_Technical">QA and Technical</option>
      <option value="Supply_Chain">Supply Chain</option>
    </select>
  </div>
  <div id="Layer10"><img src="subframev02.png" width="200" height="44" /></div>
  <div id="Layer13"><img src="subframev02.png" width="80" height="40" /></div>

<div id="Layer14">
  <input type="submit" name="Submit" value="Submit" />
</div>
</form>
</body>
</html>



this is my code for the condition.php
<?php
$host="localhost";
$username="root";
$password="";
$db_name="dspi";


mysql_connect("$host", "$username", "$password") or die("Cannot connect to server");
mysql_select_db("$db_name")or die("Cannot select DB"); 


$department = mysql_real_escape_string($_POST['department']);  
$sql="SELECT Department FROM tbllogin WHERE Department = $department";  
$result=mysql_query($sql);  

  
    if($row['Department']=='Accounting')
		{
			header('location:accounting.php');
		}
	if($row['Department']=='Engineering')
		{
			header('location:engineering.php');
		}
    if($row['Department']=='Finishing_Goods')
		{
			header('location:finishing_goods.php');
		}
    if($row['Department']=='HRAD')
		{
			header('location:HRAD.php');
		}
    if($row['Department']=='MIS')
		{
			header('location:MIS.php');
		}
    if($row['Department']=='Packaging_and_Design')
		{
			header('location:packaging_design.php');
		}
    if($row['Department']=='Production')
		{
			header('location:production.php');
		}
    if($row['Department']=='Purchasing_Logistic')
		{
			header('location:purchasing_logistic.php');
		}
    if($row['Department']=='QA_and_Technical')
		{
			header('location:QA_technical.php');
		}
    if($row['Department']=='Supply_Chain')
		{
			header('location:supply_chain.php');
		}
	
     // do your redirect stuff here.  

 else 

 {  

     echo "Error: There is no department by that name.";  

 } 
?>



When i run my webpage in nusphere and i choose the accounting and i click the submit button the result is error: There is no department by that name:
it means my if statement is wrong... How can i correctmy statement...
Was This Post Helpful? 0
  • +
  • -

#20 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5313
  • View blog
  • Posts: 27,216
  • Joined: 10-May 07

Re: Cannot run my if statement

Posted 07 July 2010 - 06:45 PM

How is this topic different than the others that you have open?
Was This Post Helpful? 0
  • +
  • -

#21 Rhoda Rose  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 93
  • Joined: 21-June 10

Re: Cannot run my if statement

Posted 07 July 2010 - 06:48 PM

I revised my code

this is my code for the form.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=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
#Layer1 {
	position:absolute;
	width:200px;
	height:115px;
	z-index:1;
	left: 21px;
	top: 228px;
}
#Layer2 {
	position:absolute;
	width:267px;
	height:115px;
	z-index:1;
	left: 425px;
	top: 238px;
}
#Layer3 {
	position:absolute;
	width:329px;
	height:89px;
	z-index:1;
	left: 478px;
	top: 298px;
}
#Layer4 {
	position:absolute;
	width:197px;
	height:34px;
	z-index:2;
	left: 15px;
	top: 35px;
}
.style1 {
	font-size: 12px;
	font-family: Verdana, Arial, Helvetica, sans-serif;
}
#Layer5 {
	position:absolute;
	width:376px;
	height:83px;
	z-index:2;
	left: 361px;
	top: 329px;
}
#Layer6 {
	position:absolute;
	width:327px;
	height:36px;
	z-index:3;
	left: 377px;
	top: 341px;
}
#Layer7 {
	position:absolute;
	width:99px;
	height:56px;
	z-index:4;
	left: 567px;
	top: 395px;
}
#Layer8 {
	position:absolute;
	width:66px;
	height:35px;
	z-index:5;
	left: 393px;
	top: 355px;
}
#Layer9 {
	position:absolute;
	width:187px;
	height:36px;
	z-index:6;
	left: 112px;
	top: 131px;
}
#Layer10 {
	position:absolute;
	width:298px;
	height:65px;
	z-index:7;
	left: 475px;
	top: 262px;
}
#Layer11 {
	position:absolute;
	width:122px;
	height:57px;
	z-index:8;
	left: 364px;
	top: 315px;
}
#Layer12 {
	position:absolute;
	width:182px;
	height:31px;
	z-index:9;
	left: 489px;
	top: 271px;
}
#Layer13 {
	position:absolute;
	width:80px;
	height:41px;
	z-index:10;
	left: 547px;
	top: 334px;
}
#Layer14 {
	position:absolute;
	width:58px;
	height:26px;
	z-index:11;
	left: 555px;
	top: 340px;
}
-->
</style>
</head>
<body background="bgroundv03.png" bgproperties="fixed">
<form id="form1" name="form1" method="post" action="loginv05.php">
 
  <div id="Layer12">
 
    <select name="department">
      <option>Choose your Department</option>
      <option value="Accounting">Accounting</option>
      <option value="Engineering">Engineering</option>
      <option value="Finishing_Goods">Finishing Goods</option>
      <option value="HRAD">HRAD</option>
      <option value="MIS">MIS</option>
      <option value="Packaging_and_Design">Packaging and Design</option>
      <option value="Production">Production</option>
      <option value="Purchasing_Logistic">Purchasing and Logistics</option>
      <option value="QA_and_Technical">QA and Technical</option>
      <option value="Supply_Chain">Supply Chain</option>
    </select>
  </div>
  <div id="Layer10"><img src="subframev02.png" width="200" height="44" /></div>
  <div id="Layer13"><img src="subframev02.png" width="80" height="40" /></div>

<div id="Layer14">
  <input type="submit" name="Submit" value="Submit" />
</div>
</form>
</body>
</html>



this is my code for the condition.php
<?php
$host="localhost";
$username="root";
$password="";
$db_name="dspi";


mysql_connect("$host", "$username", "$password") or die("Cannot connect to server");
mysql_select_db("$db_name")or die("Cannot select DB"); 


$department = mysql_real_escape_string($_POST['department']);  
$sql="SELECT Department FROM tbllogin WHERE Department = $department";  
$result=mysql_query($sql);  

  
    if($row['Department']=='Accounting')
		{
			header('location:accounting.php');
		}
	if($row['Department']=='Engineering')
		{
			header('location:engineering.php');
		}
    if($row['Department']=='Finishing_Goods')
		{
			header('location:finishing_goods.php');
		}
    if($row['Department']=='HRAD')
		{
			header('location:HRAD.php');
		}
    if($row['Department']=='MIS')
		{
			header('location:MIS.php');
		}
    if($row['Department']=='Packaging_and_Design')
		{
			header('location:packaging_design.php');
		}
    if($row['Department']=='Production')
		{
			header('location:production.php');
		}
    if($row['Department']=='Purchasing_Logistic')
		{
			header('location:purchasing_logistic.php');
		}
    if($row['Department']=='QA_and_Technical')
		{
			header('location:QA_technical.php');
		}
    if($row['Department']=='Supply_Chain')
		{
			header('location:supply_chain.php');
		}
	
     // do your redirect stuff here.  

 else 

 {  

     echo "Error: There is no department by that name.";  

 } 
?>



When i run my webpage in nusphere and i choose the accounting and i click the submit button the result is error: There is no department by that name:
it means my if statement is wrong... How can i correctmy statement...
Was This Post Helpful? 0
  • +
  • -

#22 Rhoda Rose  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 93
  • Joined: 21-June 10

Re: Cannot run my if statement

Posted 07 July 2010 - 06:50 PM

I revised my code

this is my code for the form.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=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
#Layer1 {
	position:absolute;
	width:200px;
	height:115px;
	z-index:1;
	left: 21px;
	top: 228px;
}
#Layer2 {
	position:absolute;
	width:267px;
	height:115px;
	z-index:1;
	left: 425px;
	top: 238px;
}
#Layer3 {
	position:absolute;
	width:329px;
	height:89px;
	z-index:1;
	left: 478px;
	top: 298px;
}
#Layer4 {
	position:absolute;
	width:197px;
	height:34px;
	z-index:2;
	left: 15px;
	top: 35px;
}
.style1 {
	font-size: 12px;
	font-family: Verdana, Arial, Helvetica, sans-serif;
}
#Layer5 {
	position:absolute;
	width:376px;
	height:83px;
	z-index:2;
	left: 361px;
	top: 329px;
}
#Layer6 {
	position:absolute;
	width:327px;
	height:36px;
	z-index:3;
	left: 377px;
	top: 341px;
}
#Layer7 {
	position:absolute;
	width:99px;
	height:56px;
	z-index:4;
	left: 567px;
	top: 395px;
}
#Layer8 {
	position:absolute;
	width:66px;
	height:35px;
	z-index:5;
	left: 393px;
	top: 355px;
}
#Layer9 {
	position:absolute;
	width:187px;
	height:36px;
	z-index:6;
	left: 112px;
	top: 131px;
}
#Layer10 {
	position:absolute;
	width:298px;
	height:65px;
	z-index:7;
	left: 475px;
	top: 262px;
}
#Layer11 {
	position:absolute;
	width:122px;
	height:57px;
	z-index:8;
	left: 364px;
	top: 315px;
}
#Layer12 {
	position:absolute;
	width:182px;
	height:31px;
	z-index:9;
	left: 489px;
	top: 271px;
}
#Layer13 {
	position:absolute;
	width:80px;
	height:41px;
	z-index:10;
	left: 547px;
	top: 334px;
}
#Layer14 {
	position:absolute;
	width:58px;
	height:26px;
	z-index:11;
	left: 555px;
	top: 340px;
}
-->
</style>
</head>
<body background="bgroundv03.png" bgproperties="fixed">
<form id="form1" name="form1" method="post" action="loginv05.php">
 
  <div id="Layer12">
 
    <select name="department">
      <option>Choose your Department</option>
      <option value="Accounting">Accounting</option>
      <option value="Engineering">Engineering</option>
      <option value="Finishing_Goods">Finishing Goods</option>
      <option value="HRAD">HRAD</option>
      <option value="MIS">MIS</option>
      <option value="Packaging_and_Design">Packaging and Design</option>
      <option value="Production">Production</option>
      <option value="Purchasing_Logistic">Purchasing and Logistics</option>
      <option value="QA_and_Technical">QA and Technical</option>
      <option value="Supply_Chain">Supply Chain</option>
    </select>
  </div>
  <div id="Layer10"><img src="subframev02.png" width="200" height="44" /></div>
  <div id="Layer13"><img src="subframev02.png" width="80" height="40" /></div>

<div id="Layer14">
  <input type="submit" name="Submit" value="Submit" />
</div>
</form>
</body>
</html>



this is my code for the condition.php
<?php
$host="localhost";
$username="root";
$password="";
$db_name="dspi";


mysql_connect("$host", "$username", "$password") or die("Cannot connect to server");
mysql_select_db("$db_name")or die("Cannot select DB"); 


$department = mysql_real_escape_string($_POST['department']);  
$sql="SELECT Department FROM tbllogin WHERE Department = $department";  
$result=mysql_query($sql);  

  
    if($row['Department']=='Accounting')
		{
			header('location:accounting.php');
		}
	if($row['Department']=='Engineering')
		{
			header('location:engineering.php');
		}
    if($row['Department']=='Finishing_Goods')
		{
			header('location:finishing_goods.php');
		}
    if($row['Department']=='HRAD')
		{
			header('location:HRAD.php');
		}
    if($row['Department']=='MIS')
		{
			header('location:MIS.php');
		}
    if($row['Department']=='Packaging_and_Design')
		{
			header('location:packaging_design.php');
		}
    if($row['Department']=='Production')
		{
			header('location:production.php');
		}
    if($row['Department']=='Purchasing_Logistic')
		{
			header('location:purchasing_logistic.php');
		}
    if($row['Department']=='QA_and_Technical')
		{
			header('location:QA_technical.php');
		}
    if($row['Department']=='Supply_Chain')
		{
			header('location:supply_chain.php');
		}
	
     // do your redirect stuff here.  

 else 

 {  

     echo "Error: There is no department by that name.";  

 } 
?>



When i run my webpage in nusphere and i choose the accounting and i click the submit button the result is error: There is no department by that name:
it means my if statement is wrong... How can i correctmy statement...
Was This Post Helpful? -1
  • +
  • -

#23 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5313
  • View blog
  • Posts: 27,216
  • Joined: 10-May 07

Re: Cannot run my if statement

Posted 07 July 2010 - 06:53 PM

View PostRhoda Rose, on 07 July 2010 - 07:48 PM, said:

How can i correctmy statement...

All four topics merged. There is no need for four topics asking the same question & posting the same code.
Was This Post Helpful? 2
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2