Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Switch Problem

Status
Not open for further replies.

tekpr00

IS-IT--Management
Jan 22, 2008
186
CA
Can anyone tell me what I am doing wrong here? My switch will not dispaly contents of preoffession. Thanks in advance.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] xml:lang="en" lang="en">
 <head>
  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
  
  <title> Professional Title and Contents </title>
  <style type="text/css" media="screen">.error {color: red ;} </style>
 </head>
 <body>

 <form action="selector.php" method="post">

<p>Profession:
<select name ="profession">
<option value="">Pick One</option>
<option value="engineering">Engineering</option>
<option value="botany">Botany</option>
<option value="woodcarving">Woodcarving</option>
<option value="familydoctor">Family Doctor</option>
<option value="architecture">Architecture</option>
</select></p>

<input type="submit" name="submit"
 value="Select" />

 </form>

<?php 

switch ('profession'){
	case 'engineering':
		echo "Engineering is the discipline, art, skill and profession of acquiring and applying scientific, mathematical, economic, social, and practical knowledge, in order to design and build structures, machines, devices, systems, materials and processes that safely realize improvements to the lives of people.";
	break;
	case 'botany':
		echo "Botany is a branch of biology that involves the scientific study of plant life. Botany covers a wide range of scientific disciplines including structure, growth, reproduction, metabolism, development, diseases, chemical properties, and evolutionary relationships among taxonomic groups. Botany began with early human efforts to identify edible, medicinal and poisonous plants, making it one of the oldest sciences. Today botanists study over 550,000 species of living organisms.";
	break;
	case 'woodcarving':
		echo "Wood carving (xyloglyphy) is a form of working wood by means of a cutting tool (knife) in one hand or a chisel by two hands or with one hand on a chisel and one hand on a mallet, resulting in a wooden figure or figurine, or in the sculptural ornamentation of a wooden object. The phrase may also refer to the finished product, from individual sculptures, to hand-worked mouldings composing part of a tracery.";
	break;
	case 'familydoctor':
		echo "Family medicine (FM) is a medical specialty devoted to comprehensive health care for people of all ages. It is a division of primary care that provides continuing and comprehensive health care for the individual and family across all ages, sexes, diseases, and parts of the body.[1] It is based on knowledge of the patient in the context of the family and the community, emphasizing disease prevention and health promotion.[2] According to the World Organization of Family Doctors (Wonca), the aim of family medicine is to provide personal, comprehensive and continuing care for the individual in the context of the family and the community";
	break;
	case 'architecture':
		echo "Architecture (Latin architectural, from the Greek ἀρχιτέκτων – arkhitekton, from builder, carpenter, mason is both the process and product of planning, designing and construction. Architectural works, in the material form of buildings, are often perceived as cultural and political symbols and as works of art. Historical civilizations are often identified with their surviving architectural achievements. ";
	break;
}//end of switch
?>
</body>
</html>

it is suppose to display content under select button. But it is not.
Profession:
 
switch ('profession')

1. You are attempting to perform a case switch on a string.
That can never work. Because the text "profession' will never change.

You want to perform the switch on a variable, so depending on the value of it it will perform the actions in a specific case.

2. You are assuming incorrectly that the input name will automatically create a variable, it does not, you need to use the $_POST array to get the submitted value from it.

So:

Code:
<?php 

[red]$profession=$_POST['profession'];[/red]
switch ([red]$profession[/red]){


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Thank you for the variable suggestion, even with your suggestion ther is no show - print

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] xml:lang="en" lang="en">
 <head>
  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
  
  <title> Professional Title and Contents </title>
  <style type="text/css" media="screen"> </style>
 </head>
 <body>

 <form action="selector.php" method="post">

<p>Profession:
<select name ="profession">
<option value="">Pick One</option>
<option value="engineering">Engineering</option>
<option value="botany">Botany</option>
<option value="woodcarving">Woodcarving</option>
<option value="familydoctor">Family Doctor</option>
<option value="architecture">Architecture</option>
</select></p>

<input type="submit" name="submit"
 value="Select" />



<?php 

$profession=$_POST['profession'];
switch ($profession){
	case 'engineering':
		print '<p Engineering is the discipline, art, skill and profession of acquiring and applying scientific, mathematical, economic, social, and practical knowledge, in order to design and build structures, machines, devices, systems, materials and processes that safely realize improvements to the lives of people.</p>';
	break;
	case 'botany':
		print '<p Botany is a branch of biology that involves the scientific study of plant life. Botany covers a wide range of scientific disciplines including structure, growth, reproduction, metabolism, development, diseases, chemical properties, and evolutionary relationships among taxonomic groups. Botany began with early human efforts to identify edible, medicinal and poisonous plants, making it one of the oldest sciences. Today botanists study over 550,000 species of living organisms.</p>';
	break;
	case 'woodcarving':
		print'<p Wood carving (xyloglyphy) is a form of working wood by means of a cutting tool (knife) in one hand or a chisel by two hands or with one hand on a chisel and one hand on a mallet, resulting in a wooden figure or figurine, or in the sculptural ornamentation of a wooden object. The phrase may also refer to the finished product, from individual sculptures, to hand-worked mouldings composing part of a tracery.</p>';
	break;
	case 'familydoctor':
		print '<p Family medicine (FM) is a medical specialty devoted to comprehensive health care for people of all ages. It is a division of primary care that provides continuing and comprehensive health care for the individual and family across all ages, sexes, diseases, and parts of the body.[1] It is based on knowledge of the patient in the context of the family and the community, emphasizing disease prevention and health promotion.[2] According to the World Organization of Family Doctors (Wonca), the aim of family medicine is to provide personal, comprehensive and continuing care for the individual in the context of the family and the community</p>';
	break;
	case 'architecture':
		print '<p Architecture (Latin architectural, from the Greek arkhitekton, from builder, carpenter, mason is both the process and product of planning, designing and construction. Architectural works, in the material form of buildings, are often perceived as cultural and political symbols and as works of art. Historical civilizations are often identified with their surviving architectural achievements. </p>';
	break;
}//end of switch
?>
</form>
</body>
</html>
 
Its not a PHP issue, but down to an HTML problem. Your <p> elements aren't properly closed so all your text ends up inside the P tag as a property rather than actual text.

If you look at the source of your page after pressing your select button, you'll see the text is there, but is not shown.

Close your <p> tags like this:

Code:
 print'<p[COLOR=white red]>[/color] Wood carving (xyloglyphy) is a form of working wood by means of a cutting tool (knife) in one hand or a chisel by two hands or with one hand on a chisel and one hand on a mallet, resulting in a wooden figure or figurine, or in the sculptu...</p>

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Thanks for your pointer...I wonder why it did not show up during HTML validation.

Again, thanks for advice and patience.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top