2 Replies - 341 Views - Last Post: 08 July 2010 - 03:03 AM Rate Topic: -----

#1 Rhoda Rose  Icon User is offline

  • D.I.C Head

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

Problem in fetching rows to compare the option value to the row in the

Posted 08 July 2010 - 02:35 AM

I have a problem in coding regarding comparing the option value to the field row in my database. I want that when i run my webpage and i choose the accounting department and i click the submit button i will automatically link top accountnig webpage..
this is my code for 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="condition.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>


and this is my code in condition.php


<?php
 include 'conn.php'; 
 
$department = mysql_real_escape_string($_POST['department']);  
$sql="SELECT Department FROM tbllogin WHERE Department = $department";  
$result=mysql_query($sql); 
$row = mysql_fetch_array($result); 



    if($row['Department']=='Accounting')
		{
			header('location:accounting.php');
		}
	elseif($row['Department']=='Engineering')
		{
			header('location:engineering.php');
		}
    elseif($row['Department']=='Finishing_Goods')
		{
			header('location:finishing_goods.php');
		}
    elseif($row['Department']=='HRAD')
		{
			header('location:HRAD.php');
		}
    elseif($row['Department']=='MIS')
		{
			header('location:MIS.php');
		}
    elseif($row['Department']=='Packaging_and_Design')
		{
			header('location:packaging_design.php');
		}
    elseif($row['Department']=='Production')
		{
			header('location:production.php');
		}
    elseif($row['Department']=='Purchasing_Logistic')
		{
			header('location:purchasing_logistic.php');
		}
    elseif($row['Department']=='QA_and_Technical')
		{
			header('location:QA_technical.php');
		}
    elseif($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 i got an error like this:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in F:\Php Projects\loginv05.php on line 7
Error: There is no department by that name.



and when i change the mysql_fetch array() to mysql_fetch_assoc() the error is

Warning: mysql_fetch_assoc()(): supplied argument is not a valid MySQL result resource in F:\Php Projects\loginv05.php on line 7
Error: There is no department by that name.
[/COLOR]

I don't know what should be the code to run my condition..

I hope you can help me...

Thank you...

This post has been edited by Rhoda Rose: 08 July 2010 - 02:36 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Problem in fetching rows to compare the option value to the row in the

#2 Valek  Icon User is offline

  • The Real Skynet
  • member icon

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

Re: Problem in fetching rows to compare the option value to the row in the

Posted 08 July 2010 - 02:59 AM

Well, from waht I see, your query was failing (because the value of $department was a string and was not inside single quotes), and you were not checking to see whether the query was valid or not (by adding or die(mysql_error()) after mysql_query() and before the semi-colon).

With these two issues accounted for and corrected, your code for condition.php would be as it appears below.

<?php
include 'conn.php'; 
 
$department = mysql_real_escape_string($_POST['department']);  
$sql="SELECT Department FROM tbllogin WHERE Department = '$department'";  
$result = mysql_query($sql) or die(mysql_error()); 
$row = mysql_fetch_assoc($result); 

if($row['Department']=='Accounting')
{
	header('location:accounting.php');
}
elseif($row['Department']=='Engineering')
{
	header('location:engineering.php');
}
elseif($row['Department']=='Finishing_Goods')
{
	header('location:finishing_goods.php');
}
elseif($row['Department']=='HRAD')
{
	header('location:HRAD.php');
}
elseif($row['Department']=='MIS')
{
	header('location:MIS.php');
}
elseif($row['Department']=='Packaging_and_Design')
{
	header('location:packaging_design.php');
}
elseif($row['Department']=='Production')
{
	header('location:production.php');
}
elseif($row['Department']=='Purchasing_Logistic')
{
	header('location:purchasing_logistic.php');
}
elseif($row['Department']=='QA_and_Technical')
{
	header('location:QA_technical.php');
}
elseif($row['Department']=='Supply_Chain')
{
	header('location:supply_chain.php');
} 
else 
{  
	echo "Error: There is no department by that name.";  
} 
?>
	


This post has been edited by Valek: 08 July 2010 - 03:02 AM

Was This Post Helpful? 0
  • +
  • -

#3 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5249
  • View blog
  • Posts: 27,073
  • Joined: 10-May 07

Re: Problem in fetching rows to compare the option value to the row in the

Posted 08 July 2010 - 03:03 AM

Please reply to your original topic. There is no need to open a new topic for each question.

I asked nice, three times, just like I asked you about the code tags. You only seem to respond when you're topics are closed. Shoot me a private message if you need help navigating the site. Sorry, but we can't fix every post you make... it gets old after a while.
Was This Post Helpful? 3
  • +
  • -

Page 1 of 1