PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
scristaldi
Forum Newbie
Posts: 5 Joined: Wed Apr 08, 2009 4:42 pm
Post
by scristaldi » Mon Nov 29, 2010 2:32 pm
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:
  
<?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 ***************************************
 
Select g
    
<?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 />";
}
?>
Last edited by
Benjamin on Mon Nov 29, 2010 3:59 pm, edited 1 time in total.
Reason: Added [syntax=php] tags.
curlybracket
Forum Commoner
Posts: 59 Joined: Mon Nov 29, 2010 2:40 pm
Post
by curlybracket » Mon Nov 29, 2010 2:46 pm
You should use syntax highlight, otherwise it's impossible to read Your code.
scristaldi
Forum Newbie
Posts: 5 Joined: Wed Apr 08, 2009 4:42 pm
Post
by scristaldi » Mon Nov 29, 2010 3:01 pm
Sorry. this is the specific code I think.
Code: Select all
<div>
<fieldset>
Select title:
  
<?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 ***************************************
 
Select g
    
<?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">
Last edited by
Benjamin on Mon Nov 29, 2010 4:00 pm, edited 1 time in total.
Reason: Added [syntax=php] tags.
curlybracket
Forum Commoner
Posts: 59 Joined: Mon Nov 29, 2010 2:40 pm
Post
by curlybracket » Mon Nov 29, 2010 3:05 pm
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.
scristaldi
Forum Newbie
Posts: 5 Joined: Wed Apr 08, 2009 4:42 pm
Post
by scristaldi » Thu Dec 02, 2010 10:22 am
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:
  
<?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 ***************************************
 
Select g
    
<?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 />";
}
?>