22 Replies - 934 Views - Last Post: 07 July 2010 - 06:53 PM
#1
Cannot run my if statement
Posted 05 July 2010 - 07:28 PM
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.
Replies To: Cannot run my if statement
#2
Re: Cannot run my if statement
Posted 05 July 2010 - 08:50 PM
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...
#3
Re: Cannot run my if statement
Posted 05 July 2010 - 09:01 PM
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 '<>')
#4
Re: Cannot run my if statement
Posted 05 July 2010 - 09:13 PM
#5
Re: Cannot run my if statement
Posted 05 July 2010 - 09:33 PM
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.)
#6
Re: Cannot run my if statement
Posted 05 July 2010 - 10:58 PM
#7
Re: Cannot run my if statement
Posted 05 July 2010 - 11:11 PM
#8
Re: Cannot run my if statement
Posted 05 July 2010 - 11:44 PM
#9
Re: Cannot run my if statement
Posted 05 July 2010 - 11:47 PM
#10
Re: Cannot run my if statement
Posted 06 July 2010 - 12:16 AM
#11
Re: Cannot run my if statement
Posted 06 July 2010 - 12:19 AM
This post has been edited by Valek: 06 July 2010 - 12:20 AM
#12
Re: Cannot run my if statement
Posted 06 July 2010 - 12:19 AM
#13
Re: Cannot run my if statement
Posted 06 July 2010 - 12:22 AM
Rhoda Rose said:
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.
#14
Re: Cannot run my if statement
Posted 06 July 2010 - 12:26 AM
#15
Re: Cannot run my if statement
Posted 07 July 2010 - 06:21 PM
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...
|
|

New Topic/Question
Reply




MultiQuote





|