Cannot run my if statement

  • (2 Pages)
  • +
  • 1
  • 2

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

#1 Rhoda Rose  Icon User is offline

  • D.I.C Head

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

Cannot run my if statement

Posted 05 July 2010 - 07:28 PM

good day!

how can i compare the option value to the field in my database and when the value in the option that was choose is equal to the database it automatically link to the webpage that they belong.
Is This A Good Question/Topic? 0
  • +

Replies To: Cannot run my if statement

#2 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 05 July 2010 - 08:50 PM

I use php 4.3.1, mysql, and xampp
I have a database name dspi and table name tbllogin and it has a field Username and Department, I have a 10 departments including accounting, engineering, etc. Then i create a webpage for choosing what department they want to go. I use list value. I want that if they choose accounting and they click the submit button they automatically go to accounting webpage. I don't know how can i do that.

this is my code:
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>
</form>
<div id="Layer14">
  <input type="submit" name="Submit" value="Submit" />
</div>
</body>
</html>




loginv05.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']);  
 $query = "SELECT Department FROM tbllogin";  
 $result = mysql_query($query) or die(mysql_error());  
 
 if(mysql_num_rows($result) === 1)  

 {  
	if($department=='Accounting')
		{
			header('location:accounting.php');
		}
	if($department=='Engineering')
		{
			header('location:engineering.php');
		}
	if($department=='Finishng_Goods')
		{
			header('location:finishing_goods.php');
		}
	if($department=='HRAD')
		{
			header('location:HRAD.php');
		}
	if($department=='MIS')
		{
			header('location:MIS.php');
		}
	if($department=='Packaging_and_Design')
		{
			header('location:packaging_design.php');
		}
	if($department=='Production')
		{
			header('location:production.php');
		}
	if($department=='Purchasing_Logistic')
		{
			header('location:purchasing_logistic.php');
		}
	if($department=='QA_and_Technical')
		{
			header('location:QA_technical.php');
		}
	if($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 theres nothing happened. So that I don't know why my code did not run...

I hope you can help me..
Thank you...
Was This Post Helpful? 0
  • +
  • -

#3 KYA  Icon User is online

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3120
  • View blog
  • Posts: 19,166
  • Joined: 14-September 07

Re: Cannot run my if statement

Posted 05 July 2010 - 09:01 PM

*Moved to PHP*

The 'Programmers' sub forums are for more 'discussion' oriented threads rather then 'help' threads.


Also, code tags are BBcode (i.e. they use brackets rather then html '<>')
Was This Post Helpful? 0
  • +
  • -

#4 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 543
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: Cannot run my if statement

Posted 05 July 2010 - 09:13 PM

I know from your other thread that you've been using IIS (though I don't recall waht version, or if you even mentioned the version). Have you checked to make sure PHP errors are being logged appropriately? It's quite common for PHP errors to be squelched by IIS by default as a security measure. there's a thread here that could be useful to you in making sure you're not encountering any errors.
Was This Post Helpful? 0
  • +
  • -

#5 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: Cannot run my if statement

Posted 05 July 2010 - 09:33 PM

You 1) submit the form to PHP, 2) have PHP fetch the option from the submitted form and execute a query against your database, and 3) print out any results or use header('Location: ...') to redirect.

Try it. See how far you get. Let us know if you have more targeted questions. (And keep in mind: we like code examples, preferably inside [code] tags; error messages; and detailed explanations.)
Was This Post Helpful? 0
  • +
  • -

#6 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 05 July 2010 - 10:58 PM

my other webpage work properly except this webpage. I don't what is the problem in my code.
Was This Post Helpful? 0
  • +
  • -

#7 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 543
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: Cannot run my if statement

Posted 05 July 2010 - 11:11 PM

As I mentioned above, you could be getting an error and your web server's configuration could be preventing them from displaying (or even logging). Please check out the link I posted above as it is relevant to your problem (although the method for fixing it could be slightly different if you're using a different version of IIS than 7).
Was This Post Helpful? 0
  • +
  • -

#8 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 05 July 2010 - 11:44 PM

the IIS that i'm using is IIS 5.1
Was This Post Helpful? 0
  • +
  • -

#9 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 543
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: Cannot run my if statement

Posted 05 July 2010 - 11:47 PM

Are any PHP pages working at all on your server (I notice there are multiple reports of errors running PHP5 on IIS 5.1). Also, check php.ini to ensure the log_errors directive is set to On.
Was This Post Helpful? 0
  • +
  • -

#10 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 06 July 2010 - 12:16 AM

what is another syntax to link to another webpage if the header was not running
Was This Post Helpful? 0
  • +
  • -

#11 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 543
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: Cannot run my if statement

Posted 06 July 2010 - 12:19 AM

header() is the generally accepted way to do it. It just occurred to me something that I've overlooked, as well. You should ensure any script you're running that calls header() doesn't have any output (including whitespace such as spaces, tabs, or line breaks) before the header() call, as by then the headers will have already been sent, and so you cannot alter them or add any.

This post has been edited by Valek: 06 July 2010 - 12:20 AM

Was This Post Helpful? 0
  • +
  • -

#12 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 06 July 2010 - 12:19 AM

the version of php that I am using is php 4.3.10
Was This Post Helpful? 0
  • +
  • -

#13 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 543
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: Cannot run my if statement

Posted 06 July 2010 - 12:22 AM

Rhoda Rose said:

Yesterday, I use php4.3.10 and i run my webpage but now i used php 5.3.2 I encountered this problem. I don't know if I have a problem in my IIS and PHP installation.


This post made me think you were using PHP 5.3.2. The comments about header() and no output beforehand, and checking the log_errors directive still apply.
Was This Post Helpful? 0
  • +
  • -

#14 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5394
  • View blog
  • Posts: 27,388
  • Joined: 10-May 07

Re: Cannot run my if statement

Posted 06 July 2010 - 12:26 AM

View PostRhoda Rose, on 06 July 2010 - 01:16 AM, said:

what is another syntax to link to another webpage if the header was not running

You can use meta refresh, but it's frowned upon because it can be disabled on the clients browser so it isn't a guaranteed way to assure a page move.
Was This Post Helpful? 0
  • +
  • -

#15 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:21 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
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2