Troubleshooting First Script

From: Date: Wed, 28 Jun 2000 17:00:30 +0000
Subject: Troubleshooting First Script
Groups: php.general 
Request: Send a blank email to php-general+get-3601@lists.php.net to get a copy of this message
Hi; Upon selection of the fields and submission of the form, my script doesn't return anything but the header: *Here's Your Horses!* This is true even when *nothing* is selected and the default should say, in essence, select something! Would someone please take a look at my code and see what I'm doing wrong? A few periods *.* have been thrown in so (hopefully!) it doesn't try to render itself in anyone's email client. TIA, BenO <.HTML> <.HEAD> <TITLE>Find a Horse!</TITLE> <./HEAD> <.BODY> <?
/* Script Name:    Antigo_search.php3 */
/* First let's set some variables. */ require ("/usr/www/thewebso/SSL/Common/common.req"); /* Establish our connection to the DB. */ mysql_pconnect("$hostname","$user","$password") or die("Unable to connect to SQL server"); mysql_select_db("thewebso") or die("Unable to select database"); /* Now to define functions. */ /* The main screen. Printed when $state is empty. */ /* Rem */ function Main_Menu () { echo "<H1><CENTER> Find A Horse! </CENTER></H1>"; echo "Please fill out as much information as you'd like, then hit the &quot;Find a Horse!&quot; button.<br>&nbsp;<br>"; echo "<FORM METHOD = \"POST\" ACTION=\"Antigo_search.php3\">"; echo "Color<br>"; echo "<select name=\"color\">"; /* SHOULD I BE PUTTING *NAME* IN BOTH SELECT AND OPTION? */ echo "<option selected name=\"color\" value=\"9\">select</option>"; /* This is simply to set a value so far out that it'll never be filled. */ echo "<option name=\"color\" value=\"3\">Palomino</option>"; echo "<option name=\"color\" value=\"1\">Chestnut</option>"; echo "<option name=\"color\" value=\"0\">Bay</option>"; echo "<option name=\"color\" value=\"4\">Golden</option>"; echo "<option name=\"color\" value=\"2\">Buckskin</option>"; echo "</select><br>"; echo "Gender<br>"; echo "<select name=\"gender\">"; echo "<option selected name=\"gender\" value=\"9\">select</option>"; echo "<option name=\"gender\" value=\"0\">Mare</option>"; echo "<option name=\"gender\" value=\"1\">Gelding</option>"; echo "<option name=\"gender\" value=\"2\">Stallion</option>"; echo "</select><br>"; echo "Age<br>"; echo "<select name=\"age\">"; echo "<option selected name=\"age\" value=\"9\">select</option>"; echo "<option name=\"age\" value=\"0\">Yearling</option>"; echo "<option name=\"age\" value=\"1\">2-4 years</option>"; echo "<option name=\"age\" value=\"2\">4-7 years</option>"; echo "<option name=\"age\" value=\"3\">7+ years</option>"; echo "</select><br>&nbsp;<br>"; echo "<INPUT TYPE=\"submit\" name=\"state\" VALUE=\"FindHorse\">"; echo "</FORM>"; }; function Find_a_Horse () { echo "<CENTER><H2>Here's Your Horses!</CENTER></H2><P>"; if ($color != 9 && $gender !=9 && $age != 9) { // *9* is default value $query = "select name, color, gender, birth from horse order by color"; /* CAN I ORDER BY MORE THAN ONE? */ $result = mysql_query ($query) or die ("Query failed"); while ($row = mysql_fetch_row ($result)) { for ($i = 0; $i < mysql_num_fields ($result); $i++) { /* DO I NEED TO SET VARIABLES? */ $time = getdate (time()); /* DO I NEED TO DO *GETDATE* FOR EACH PIECE? */ $dateyr = $time[year]; /* as YYYY */ $datemo = $time[mon]; /* as MM (number) */ $dateda = $time[mday]; /* as DD (number) */ $birthyr = substr($row[birth],0,4); /* calc year of birth */ $birthmo = substr($row[birth],5,2); /* calc mo. of birth */ $birthda = substr($row[birth],8,2); /* calc day of birth */ $years = $dateyr - $birthyr; $months = $datemo - $birthmo; $days = $dateda - $birthda; if ($days < 0 && $months < 0) { /* still haven't reached birthdate this year */ $years = $years - 1; /* calc how many years old this horse is */ } if ($years <= 2) { $ageh = 0; } elseif ($years <= 4) { $ageh = 1; } elseif ($years <= 7) { $age = 2; } else { $ageh = 3; } if ($row["color"] == $color && $row["gender"] == $gender && $age == $ageh) { echo "<a href=\"<? $name ?>.html\"><? $name ?></a><br>"; } } } } elseif ($gender !=9 && $age != 9) { $query = "select name, gender, birth from horse order by gender"; $result = mysql_query ($query) or die ("Query failed"); while ($row = mysql_fetch_row ($result)) { for ($i = 0; $i < mysql_num_fields ($result); $i++) { /* REMEMBER TO SET VARIABLES */ $time = getdate (time()); /* DO I NEED TO DO *GETDATE* FOR EACH PIECE? */ $dateyr = $time[year]; /* as YYYY */ $datemo = $time[mon]; /* as MM (number) */ $dateda = $time[mday]; /* as DD (number) */ $birthyr = substr($row[birth],0,4); /* calc year of birth */ $birthmo = substr($row[birth],5,2); /* calc mo. of birth */ $birthda = substr($row[birth],8,2); /* calc day of birth */ $years = $dateyr - $birthyr; $months = $datemo - $birthmo; $days = $dateda - $birthda; if ($days < 0 && $months < 0) { /* still haven't reached birthdate this year */ $years = $years - 1; } if ($years <= 2) { /* calc how many years old this horse is */ $ageh = 0; } elseif ($years <= 4) { $ageh = 1; } elseif ($years <= 7) { $age = 2; } else { $ageh = 3; } if ($row["gender"] == $gender && $age == $ageh) { echo "<a href=\"<? $name ?>.html\"><? $name ?></a><br>"; } } } } elseif ($color != 9 && $age != 9) { $query = "select name, color, birth from horse order by color"; $result = mysql_query ($query) or die ("Query failed"); while ($row = mysql_fetch_row ($result)) { for ($i = 0; $i < mysql_num_fields ($result); $i++) { /* REMEMBER TO SET VARIABLES */ $time = getdate (time()); /* DO I NEED TO DO *GETDATE* FOR EACH PIECE? */ $dateyr = $time[year]; /* as YYYY */ $datemo = $time[mon]; /* as MM (number) */ $dateda = $time[mday]; /* as DD (number) */ $birthyr = substr($row[birth],0,4); /* calc year of birth */ $birthmo = substr($row[birth],5,2); /* calc mo. of birth */ $birthda = substr($row[birth],8,2); /* calc day of birth */ $years = $dateyr - $birthyr; $months = $datemo - $birthmo; $days = $dateda - $birthda; if ($days < 0 && $months < 0) { /* still haven't reached birthdate this year */ $years = $years - 1; } if ($years <= 2) { /* calc how many years old this horse is */ $ageh = 0; } elseif ($years <= 4) { $ageh = 1; } elseif ($years <= 7) { $age = 2; } else { $ageh = 3; } if ($row["color"] == $color && $age == $ageh) { echo "<a href=\"<? $name ?>.html\"><? $name ?></a><br>"; } } } } elseif ($color != 9 && $gender !=9) { $query = "select name, color, gender from horse order by color"; $result = mysql_query ($query) or die ("Query failed"); while ($row = mysql_fetch_row ($result)) { for ($i = 0; $i < mysql_num_fields ($result); $i++) { if ($row["color"] == $color && $row["gender"] == $gender) { echo "<a href=\"<? $name ?>.html\"><? $name ?></a><br>"; } } } } elseif ($age != 9) { $query = "select name, birth from horse order by birth"; $result = mysql_query ($query) or die ("Query failed"); while ($row = mysql_fetch_row ($result)) { for ($i = 0; $i < mysql_num_fields ($result); $i++) { /* REMEMBER TO SET VARIABLES */ $time = getdate (time()); /* DO I NEED TO DO *GETDATE* FOR EACH PIECE? */ $dateyr = $time[year]; /* as YYYY */ $datemo = $time[mon]; /* as MM (number) */ $dateda = $time[mday]; /* as DD (number) */ $birthyr = substr($row[birth],0,4); /* calc year of birth */ $birthmo = substr($row[birth],5,2); /* calc mo. of birth */ $birthda = substr($row[birth],8,2); /* calc day of birth */ $years = $dateyr - $birthyr; $months = $datemo - $birthmo; $days = $dateda - $birthda; if ($days < 0 && $months < 0) { /* still haven't reached birthdate this year */ $years = $years - 1; } if ($years <= 2) { /* calc how many years old this horse is */ $ageh = 0; } elseif ($years <= 4) { $ageh = 1; } elseif ($years <= 7) { $age = 2; } else { $ageh = 3; } if ($age == $ageh) { echo "<a href=\"<? $name ?>.html\"><? $name ?></a><br>"; } } } } elseif ($gender !=9) { $query = "select name, gender from horse order by gender"; $result = mysql_query ($query) or die ("Query failed"); while ($row = mysql_fetch_row ($result)) { for ($i = 0; $i < mysql_num_fields ($result); $i++) { if ($row["gender"] == $gender) { echo "<a href=\"<? $name ?>.html\"><? $name ?></a><br>"; } } } } elseif ($color != 9) { $query = "select name, color from horse order by color"; $result = mysql_query ($query) or die ("Query failed"); while ($row = mysql_fetch_row ($result)) { for ($i = 0; $i < mysql_num_fields ($result); $i++) { if ($row["color"] == $color) { echo "<a href=\"<? $name ?>.html\"><? $name ?></a><br>"; } } } } else echo "We have over 70 horses! Please enter at least one criteria and click the &quot;Find a Horse!&quot; button."; } /* The main loop. Call functions based on the value of $state, which gets set via a hidden INPUT TYPE. */ switch($state) { case "";
      Main_Menu();
break; case "FindHorse";
      Find_a_Horse();
      break;
} ?> <./BODY> <./HTML>

« previous php.general (#3601) next »