Page 1 of 1

Cant figure this out..

Posted: Mon Nov 29, 2010 2:32 pm
by scristaldi
Following code places two lookup boxes "Select title" & Select genus and overruns another field of Sex x female x male. I can not figure out why. Any ideas.

Code: Select all

<?php 
// Make connection to database
mysql_connect("localhost", "test", "") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("pro_diversity") or die(mysql_error());
echo "Connected to pro_diversity<br /><br />";

$Fname = $_POST["Fname"];
$Lname = $_POST["Lname"];
$gender = $_POST["gender"];
$food = $_POST["food"];
$quote = $_POST["quote"];
$education = $_POST["education"];
$FTOD = $_POST["FTOD"];
if (!isset($_POST['submit'])) { //  if page is not submitted to itself echo the form
?>

<html>
<head>
<title>Pete's Input Testing</title>
</head>
<body> 
<div style="border: 2px darkgray solid;">
<body bgcolor="lightslategray">
<!-- <p style="font-size:20px;"><b><center>Pete's Input testing</center></b></p> -->
<h3><center>Pete's input test screen.</center></h3 >

<div>
<fieldset >

First Name:<input type="text"  size="30" maxlength="12" name="Fname"><br />
Last  Name:<input type="text"  size="40" maxlength="36" name="Lname"><br />

</fieldset>
</div>
<div>
<fieldset>
Select title:
&nbsp&nbsp
<?php 
$query1 = "SELECT * FROM titles";
$result = mysql_query($query1) or die(mysql_error());
//echo "Connected to table titles";
//echo "Select a title<br />"; 
/* echo "<FORM name=\"theform\" action=\"select_titles.php\" method=\"POST\">"; /* works */ 
/* echo " <FORM name=\"theform\" method=\"POST\" action= $_SERVER['PHP_SELF']; "> */
/* echo "<form name=\"theform\" action=\"$_SERVER[PHP_SELF']\" method=\"POST\">";  */
echo "<select name=\"title_id\">"; 
echo "Select a title<br /><br />"; 
while($row = mysql_fetch_array( $result )) {
// $selected_name = $row['title_id']. " " . $row['title_name'];
echo "<option value =\"{$row['title_id']}\">{$row['title_name']} </option>";}
//echo "<\select>";
//echo "<input type=\"submit\" name=\"titles_submit\" value=\"and display\">";
echo "</form>";
/***********************************************************************/
echo "<br>";
?>

// Second select box for genus ***************************************
&nbsp
Select g
&nbsp&nbsp&nbsp&nbsp
<?php
$query2 = "SELECT * FROM genus"; 
$result = mysql_query($query2) or die(mysql_error());
//echo "Connected to table genus";
//echo "<form name=\"theform\" action=\"select_genus.php\"method=\"POST\">"; 
echo "<select name=\"genus_id\">"; 
//echo "Select a genus"; 
while($row = mysql_fetch_array( $result )) {
// $selected_name = $row['genus_id']. " " . $row['genus_name'];
echo "<option value =\"{$row['genus_id']}\">{$row['genus_name']} </option>";}
//echo "<\select>";
//echo "<input type=\"submit\" name=\"genus_submit\" value=\"and display\">";
//echo "<br /><br />";
echo "</form>";
?>
</fieldset>


<!-- html work ---------------------------------------- -->
<fieldset>
<div>
Gender: <br />  
Male:<input type="radio" value="Male" name="gender">
Female:<input type="radio" value="Female" name="gender"> <br /><br />
Please choose all favorite foods: <br />
Steak:<input type="checkbox" value="Steak" name="food[]">
Pizza:<input type="checkbox" value="Pizza" name="food[]">
head cheese:<input type="checkbox" value="head cheese" name="food[]">
Chicken:<input type="checkbox" value="Chicken" name="food[]">
<br />
</fieldset>
<br />
<fieldset>
<textarea rows="3" cols="30" name="quote" wrap="physical">Enter your favorite quote!</textarea><br /><br />
Select a Level of Education:<br />
<select name="education">
<option value="Jr.High">Jr.High</option>
<option value="HighSchool">HighSchool</option>
<option value="College">College</option></select><br /><br />
Select your favorite time of day:<br />
<select name="FTOD" size="3">
<option value="Morning">Morning</option>
<option value="Day">Day</option>
<option value="Night">Night</option>
<br /> <br />
</fieldset>
</select><br />
<br /><input type="submit" value="Submit" name="submit">
<input type="reset" name="reset" value="Reset" >
</form> 

<?php
} else {

echo "Hello, ".$Fname." ".$Lname.".<br />";
echo "You are ".$gender.", and you like ";
foreach ($food as $f) {
echo $f."<br />";
}
echo "<i>".$quote."</i><br />";
echo "You're favorite time is ".$TofD.", and you passed ".$education."!<br />";
}
 
?>

Re: Cant figure this out..

Posted: Mon Nov 29, 2010 2:46 pm
by curlybracket
You should use syntax highlight, otherwise it's impossible to read Your code.

Re: Cant figure this out..

Posted: Mon Nov 29, 2010 3:01 pm
by scristaldi
Sorry. this is the specific code I think.

Code: Select all

<div>
<fieldset>
Select title:
&nbsp&nbsp
<?php
$query1 = "SELECT * FROM titles";
$result = mysql_query($query1) or die(mysql_error());
//echo "Connected to table titles";
//echo "Select a title
";
/* echo "<FORM name=\"theform\" action=\"select_titles.php\" method=\"POST\">"; /* works */
/* echo " <FORM name=\"theform\" method=\"POST\" action= $_SERVER['PHP_SELF']; "> */
/* echo "<form name=\"theform\" action=\"$_SERVER[PHP_SELF']\" method=\"POST\">"; */
echo "<select name=\"title_id\">";
echo "Select a title

";
while($row = mysql_fetch_array( $result )) {
// $selected_name = $row['title_id']. " " . $row['title_name'];
echo "<option value =\"{$row['title_id']}\">{$row['title_name']} </option>";}
//echo "<\select>";
//echo "<input type=\"submit\" name=\"titles_submit\" value=\"and display\">";
echo "</form>";
/***********************************************************************/
echo "<br>";
?>

// Second select box for genus ***************************************
&nbsp
Select g
&nbsp&nbsp&nbsp&nbsp
<?php
$query2 = "SELECT * FROM genus";
$result = mysql_query($query2) or die(mysql_error());
//echo "Connected to table genus";
//echo "<form name=\"theform\" action=\"select_genus.php\"method=\"POST\">";
echo "<select name=\"genus_id\">";
//echo "Select a genus";
while($row = mysql_fetch_array( $result )) {
// $selected_name = $row['genus_id']. " " . $row['genus_name'];
echo "<option value =\"{$row['genus_id']}\">{$row['genus_name']} </option>";}
//echo "<\select>";
//echo "<input type=\"submit\" name=\"genus_submit\" value=\"and display\">";
//echo "

";
echo "</form>";
?>
</fieldset>


<!-- html work ---------------------------------------- -->
<fieldset>
<div>
Gender:

Male:<input type="radio" value="Male" name="gender">
Female:<input type="radio" value="Female" name="gender">

Re: Cant figure this out..

Posted: Mon Nov 29, 2010 3:05 pm
by curlybracket
While editing Your post you have set of buttons over the textarea. One of them is "PHP Code", You should click it and place Your code between those two tags.

Re: Cant figure this out..

Posted: Thu Dec 02, 2010 10:22 am
by scristaldi

Code: Select all

<?php 
// Make connection to database
mysql_connect("localhost", "test", "") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("pro_diversity") or die(mysql_error());
echo "Connected to pro_diversity<br /><br />";

$Fname = $_POST["Fname"];
$Lname = $_POST["Lname"];
$gender = $_POST["gender"];
$food = $_POST["food"];
$quote = $_POST["quote"];
$education = $_POST["education"];
$FTOD = $_POST["FTOD"];
if (!isset($_POST['submit'])) { //  if page is not submitted to itself echo the form
?>

<html>
<head>
<title>Pete's Input Testing</title>
</head>
<body> 
<div style="border: 2px darkgray solid;">
<body bgcolor="lightslategray">
<!-- <p style="font-size:20px;"><b><center>Pete's Input testing</center></b></p> -->
<h3><center>Pete's input test screen.</center></h3 >

<div>
<fieldset >

First Name:<input type="text"  size="30" maxlength="12" name="Fname"><br />
Last  Name:<input type="text"  size="40" maxlength="36" name="Lname"><br />

</fieldset>
</div>
<div>
<fieldset>
Select title:
&nbsp&nbsp
<?php 
$query1 = "SELECT * FROM titles";
$result = mysql_query($query1) or die(mysql_error());
//echo "Connected to table titles";
//echo "Select a title<br />"; 
/* echo "<FORM name=\"theform\" action=\"select_titles.php\" method=\"POST\">"; /* works */ 
/* echo " <FORM name=\"theform\" method=\"POST\" action= $_SERVER['PHP_SELF']; "> */
/* echo "<form name=\"theform\" action=\"$_SERVER[PHP_SELF']\" method=\"POST\">";  */
echo "<select name=\"title_id\">"; 
echo "Select a title<br /><br />"; 
while($row = mysql_fetch_array( $result )) {
// $selected_name = $row['title_id']. " " . $row['title_name'];
echo "<option value =\"{$row['title_id']}\">{$row['title_name']} </option>";}
//echo "<\select>";
//echo "<input type=\"submit\" name=\"titles_submit\" value=\"and display\">";
echo "</form>";
/***********************************************************************/
echo "<br>";
?>

// Second select box for genus ***************************************
&nbsp
Select g
&nbsp&nbsp&nbsp&nbsp
<?php
$query2 = "SELECT * FROM genus"; 
$result = mysql_query($query2) or die(mysql_error());
//echo "Connected to table genus";
//echo "<form name=\"theform\" action=\"select_genus.php\"method=\"POST\">"; 
echo "<select name=\"genus_id\">"; 
//echo "Select a genus"; 
while($row = mysql_fetch_array( $result )) {
// $selected_name = $row['genus_id']. " " . $row['genus_name'];
echo "<option value =\"{$row['genus_id']}\">{$row['genus_name']} </option>";}
//echo "<\select>";
//echo "<input type=\"submit\" name=\"genus_submit\" value=\"and display\">";
//echo "<br /><br />";
echo "</form>";
?>
</fieldset>


<!-- html work ---------------------------------------- -->
<fieldset>
<div>
Gender: <br />  
Male:<input type="radio" value="Male" name="gender">
Female:<input type="radio" value="Female" name="gender"> <br /><br />
Please choose all favorite foods: <br />
Steak:<input type="checkbox" value="Steak" name="food[]">
Pizza:<input type="checkbox" value="Pizza" name="food[]">
head cheese:<input type="checkbox" value="head cheese" name="food[]">
Chicken:<input type="checkbox" value="Chicken" name="food[]">
<br />
</fieldset>
<br />
<fieldset>
<textarea rows="3" cols="30" name="quote" wrap="physical">Enter your favorite quote!</textarea><br /><br />
Select a Level of Education:<br />
<select name="education">
<option value="Jr.High">Jr.High</option>
<option value="HighSchool">HighSchool</option>
<option value="College">College</option></select><br /><br />
Select your favorite time of day:<br />
<select name="FTOD" size="3">
<option value="Morning">Morning</option>
<option value="Day">Day</option>
<option value="Night">Night</option>
<br /> <br />
</fieldset>
</select><br />
<br /><input type="submit" value="Submit" name="submit">
<input type="reset" name="reset" value="Reset" >
</form> 

<?php
} else {

echo "Hello, ".$Fname." ".$Lname.".<br />";
echo "You are ".$gender.", and you like ";
foreach ($food as $f) {
echo $f."<br />";
}
echo "<i>".$quote."</i><br />";
echo "You're favorite time is ".$TofD.", and you passed ".$education."!<br />";
}
 
?>