This is the entire code for the page edit_race.php

<?php

// editrace.php - edit race results

?>
<?php

// includes
 include("../includes/config.php");
 include("../includes/functions.php");

// open database connection
  $connection = mysql_connect($host, $user, $pass) or die ("Unable to
connect!");

// select database
  mysql_select_db($db) or die ("Unable to select database!");

// generate and execute query
  $get_raceresults_query = "SELECT * FROM RaceResults WHERE RaceID =
'$RaceID'";
  $get_raceresults_result = mysql_query($get_raceresults_query) or die
("Error in query: $get_raceresults_query. " . mysql_error());

// if a result is returned
if (mysql_num_rows($get_raceresults_result) >0)

 // turn it into an object
 $row = mysql_fetch_object($get_raceresults_result);

?>

<html>
<head>
<title>Race Results: Edit Race Results</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="../css/styles.css" type="text/css">
<script language="javascript" src="../scripts/CascadeMenu.js"></script>
<script language="JavaScript" src="../scripts/ts_picker4.js"></script</head>

<body OnLoad="InitMenu()" Onclick="HideMenu(menuBar)" ID="Bdy"
bgcolor="#FFFFFF" text="#000000" topmargin="0" leftmargin="0"
marginwidth="0" marginheight="0">

<form action="do_editrace.php" method="POST" enctype="multipart/form-data">
  <table width="799" border="0" cellpadding="0" cellspacing="0"
bgcolor="#ffffff">
    <tr>
      <td width="339" height="112" valign="top"
bgcolor="#0066cc">&nbsp;</td>
      <td width="460" valign="top" rowspan="2">
        <?php include ("../includes/nav.php3");?>


<input type="hidden" name="RaceID" value="<?php echo $RaceID; ?>">


      </td>
    </tr>
    <tr>
      <td height="16"></td>
    </tr>
    <tr>
      <td height="12"></td>
      <td></td>
    </tr>
  </table>
  <table width="800" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td width="10" bgcolor="#ffffff" height="25">
      <td valign="middle" colspan="2" class="raceresutlstitle"
bgcolor="#ffffff">Admin
        &gt; Add a Race</td>
      </tr>
    <tr>
      <td width="10" bgcolor="#CCCCCC">
      <td width="131" valign="middle" height="25" class="raceresutlstitle"
bgcolor="#CCCCCC">Race
        Date:</td>
      <td width="660" valign="middle" bgcolor="#CCCCCC">
<input type="Text" name="RaceDate" value="<?php echo $row->RaceDate; ?>">
</td>
    </tr>
    <tr>
      <td width="10">
      <td valign="middle" height="25" class="raceresutlstitle">Race
Name:</td>
      <td valign="middle">
        <input type="text" name="RaceName" value="<?php echo $row->RaceName;
?>">
      </td>
    </tr>
    <tr>
      <td width="10" bgcolor="#CCCCCC">
      <td valign="middle" height="25" class="raceresutlstitle"
bgcolor="#CCCCCC">Race
        Distance:</td>
      <td valign="middle" bgcolor="#CCCCCC">

<?php

// populates race distance drop-down list

$get_racedistid_query = mysql_query("SELECT * FROM RaceDistance INNER JOIN
RaceResults ON RaceDistance.RaceDistID WHERE RaceID='$RaceID'");

echo " <select name=\"RaceDistID\">\n";

while ($myrow = mysql_fetch_array($get_racedistid_query)) {

echo ' <option
value="'.$myrow["RaceDistID"].'">'.$myrow["RaceDistName"]."</option>\n";
}
echo " </select>\n";
?>

      </td>
    </tr>
    <tr>
      <td width="10">
      <td valign="middle" height="25" class="raceresutlstitle">Race Type:


</td>
<td valign="middle" class="newstxt">



<?php

// populates race type drop-down list

$get_racetypeid_query = mysql_query("SELECT * FROM RaceType INNER JOIN
RaceResults ON RaceType.RaceTypeID WHERE RaceID='$RaceID'");

echo " <select name=\"RaceTypeID\">\n";

while ($myrow = mysql_fetch_array($get_racetypeid_query)) {

echo ' <option
value="'.$myrow["RaceTypeID"].'">'.$myrow["RaceTypeName"]."</option>\n";
}
echo " </select>\n";
?>
</td>
    </tr>
    <tr>
      <td width="10" bgcolor="#CCCCCC">
      <td valign="middle" height="25" class="raceresutlstitle"
bgcolor="#CCCCCC">Race
        Time:</td>
      <td valign="middle" bgcolor="#CCCCCC"> <span class="hdtxt">HH
        <input type="text" name="RaceTimeHH" size="2" maxlength="2"
value="<? echo $row->RaceTimeHH; ?><?php if ($row->RaceTimeHH =="0") print
"0";?>">
        MM
        <input type="text" name="RaceTimeMM" size="2" maxlength="2"
value="<?php echo $row->RaceTimeMM; ?>">
        SS
        <input type="text" name="RaceTimeSS" size="2" maxlength="2"
value="<?php echo $row->RaceTimeSS; ?>">
        </span></td>
    </tr>
    <tr>
      <td width="10">
      <td valign="middle" height="25" class="raceresutlstitle">Race
Pace:</td>
      <td valign="middle"> <span class="hdtxt"> MM
        <input type="text" name="RacePaceMM" size="2" maxlength="2"
value="<? echo $row->RacePaceMM; ?>">
        SS
        <input type="text" name="RacePaceSS" size="2" maxlength="2"
value="<? echo $row->RacePaceSS; ?>">
        </span></td>
    </tr>
    <tr>
      <td width="10" bgcolor="#CCCCCC">
      <td valign="middle" height="25" class="raceresutlstitle"
bgcolor="#CCCCCC">#
        of Comp.:</td>
      <td valign="middle" bgcolor="#CCCCCC">
        <input type="text" name="RaceNumbComp" value="<?php echo
$row->RaceNumbComp; ?>">
      </td>
    </tr>
    <tr>
      <td width="10" bgcolor="#ffffff">
      <td valign="middle" height="25" class="raceresutlstitle"
bgcolor="#ffffff">Race
        Place:</td>
      <td valign="middle" bgcolor="#ffffff">
        <input type="text" name="RacePlace" value="<?php echo
$row->RacePlace; ?>">
      </td>
    </tr>
    <tr>
      <td width="10" bgcolor="#cccccc">
      <td valign="middle" height="25" class="raceresutlstitle"
bgcolor="#cccccc">Race
        City:</td>
      <td valign="middle" bgcolor="#cccccc">
<?php

// populates city drop-down list

$get_cityid_query = mysql_query("SELECT * FROM City INNER JOIN RaceResults
ON City.CityID WHERE RaceID='$RaceID'");

echo " <select name=\"CityID\">\n";

while ($myrow = mysql_fetch_array($get_cityid_query)) {

echo ' <option
value="'.$myrow["CityID"].'">'.$myrow["CityName"]."</option>\n";
}
echo " </select>\n";
?>
   </td>
    </tr>
    <tr>
      <td width="10" bgcolor="#ffffff">
      <td valign="middle" height="25" class="raceresutlstitle"
bgcolor="#ffffff">Race
        State:</td>
      <td valign="middle" bgcolor="#ffffff">

<?php

// populates state drop-down list

$get_stateid_query = mysql_query("SELECT * FROM State INNER JOIN RaceResults
ON State.StateID WHERE RaceID='$RaceID'");

echo " <select name=\"StateID\">\n";

while ($myrow = mysql_fetch_array($get_stateid_query)) {

echo ' <option value="'.$myrow["StateID"].'" if ($StateID == $StateID) print
"selected">'.$myrow["StateName"]."</option>\n";
}
echo " </select>\n";
?>

      </td>
    </tr>
 <tr>
      <td width="10" bgcolor="#cccccc">
      <td valign="middle" height="25" class="raceresutlstitle"
bgcolor="#cccccc">PR:</td>
      <td valign="middle" bgcolor="#cccccc">
  <?php

// populates pr drop-down list

$get_prid_query = mysql_query("SELECT * FROM PR INNER JOIN RaceResults ON
PR.PRID WHERE RaceID='$RaceID'");

echo " <select name=\"PRID\">\n";

while ($myrow = mysql_fetch_array($get_prid_query)) {

echo ' <option
value="'.$myrow["PRID"].'">'.$myrow["PRBinary"]."</option>\n";
}
echo " </select>\n";
?>



      </td>
    </tr>
    <tr>
      <td width="10" bgcolor="#cccccc">
      <td valign="middle" height="25" class="raceresutlstitle"
bgcolor="#cccccc">Race
        Report:</td>
      <td valign="middle" bgcolor="#cccccc">
        <textarea name="RaceReport" cols="50" rows="3" value=""><?php echo
$row->RaceReport; ?></textarea>
      </td>
    </tr>
    <tr align="center">
      <td width="10">
      <td valign="middle" colspan="2" height="28">
        <input type="submit" name="Submit" value="Update Race">
      </td>
    </tr>
  </table>
</form>

</body>
</html>

The HTML for the same page is:


<html>
<head>
<title>Race Results: Edit Race Results</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="../css/styles.css" type="text/css">
<script language="javascript" src="../scripts/CascadeMenu.js"></script>
<script language="JavaScript" src="../scripts/ts_picker4.js"></script><!--
Date input popup (American Format) reworked by Richard Perry -->
</head>

<body OnLoad="InitMenu()" Onclick="HideMenu(menuBar)" ID="Bdy"
bgcolor="#FFFFFF" text="#000000" topmargin="0" leftmargin="0"
marginwidth="0" marginheight="0">

<form action="do_editrace.php" method="POST" enctype="multipart/form-data">
  <table width="799" border="0" cellpadding="0" cellspacing="0"
bgcolor="#ffffff">
    <tr>
      <td width="339" height="112" valign="top"
bgcolor="#0066cc">&nbsp;</td>
      <td width="460" valign="top" rowspan="2">

<table width="460" border="0" cellpadding="0" cellspacing="0"
bgcolor="#0066CC">
  <tr>
    <td width="453" height="3"></td>
    <td width="7"></td>
  </tr>
  <tr>
    <td valign="top" height="48">
      <div align="right"><font face="Arial, Helvetica, sans-serif"><b><font
color="#ffffff" size="3">
        <!--BEGIN DATE -->
        March 27, 2002        <!--END DATE -->
        </font></b></font></div>
    </td>
    <td></td>
  </tr>
  <tr valign="bottom" align="right">
    <td height="51" colspan="2" bgcolor="#0066cc"><img
src="http://localhost/the-fitzgeralds/images/thefitzgeralds.trans.gif";
width="459" height="41"></td>
  </tr>
  <tr valign="middle" align="left" bgcolor="#CCCCCC">
    <td height="20" colspan="2">
      <DIV Id="menuBar" class="menuBar">
        <DIV Id="Bar1" class="Bar" menu="menu1"><a class="bar"
href="http://localhost/the-fitzgeralds/";>Home</a></DIV>
        <DIV Id="Bar2" class="Bar" menu="menu2"><a class="bar"
href="http://localhost/the-fitzgeralds/news/";>News</a></DIV>
        <DIV Id="Bar3" class="Bar" menu="menu3"><a class="bar"
href="http://localhost/the-fitzgeralds/photoalbums/";>Photo
          Album</a></DIV>
        <DIV Id="Bar4" class="Bar" menu="menu4"><a class="bar"
href="http://localhost/the-fitzgeralds/contactus/";>Contact
          Us</a></DIV>
      </DIV>
      <!--MenuItem Definition -->
      <div Id="menu1"> </DIV>
      <div Id="menu2"> </DIV>
      <div Id="menu3" class="menu">
        <div Id="menuItem3_1" class="menuItem" title="VacationPics"
cmd="http://localhost/the-fitzgeralds/photoalbums/vacationpics/index.php3";>V
acation
          Pics</DIV>
     <div Id="menuItem3_2" class="menuItem" title="partyPics"
cmd="http://localhost/the-fitzgeralds/photoalbums/partypics/index.php3";>Part
y
          Pics</DIV>

      </DIV>
      <div Id="menu4" class="menu">
        <div Id="menuItem4_1" class="menuItem" title="emailSteve"
cmd="mailto:[EMAIL PROTECTED]";>Steve</DIV>
        <div Id="menuItem4_2" class="menuItem" title="emailTammy"
cmd="mailto:[EMAIL PROTECTED]";>Tammy</DIV>
      </DIV>
  </td>
  </tr>
</table>








<input type="hidden" name="RaceID" value="1">


      </td>
    </tr>
    <tr>
      <td height="16"></td>
    </tr>
    <tr>
      <td height="12"></td>
      <td></td>
    </tr>
  </table>
  <table width="800" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td width="10" bgcolor="#ffffff" height="25">
      <td valign="middle" colspan="2" class="raceresutlstitle"
bgcolor="#ffffff">Admin
        &gt; Add a Race</td>
      </tr>
    <tr>
      <td width="10" bgcolor="#CCCCCC">
      <td width="131" valign="middle" height="25" class="raceresutlstitle"
bgcolor="#CCCCCC">Race
        Date:</td>
      <td width="660" valign="middle" bgcolor="#CCCCCC">
<input type="Text" name="RaceDate" value="2002-03-17">
</td>
    </tr>
    <tr>
      <td width="10">
      <td valign="middle" height="25" class="raceresutlstitle">Race
Name:</td>
      <td valign="middle">
        <input type="text" name="RaceName" value="An Ras Mor">
      </td>
    </tr>
    <tr>
      <td width="10" bgcolor="#CCCCCC">
      <td valign="middle" height="25" class="raceresutlstitle"
bgcolor="#CCCCCC">Race
        Distance:</td>
      <td valign="middle" bgcolor="#CCCCCC">

 <select name="RaceDistID">
 <option value="1">4 Mi</option>
 </select>

      </td>
    </tr>
    <tr>
      <td width="10">
      <td valign="middle" height="25" class="raceresutlstitle">Race Type:


</td>
<td valign="middle" class="newstxt">



 <select name="RaceTypeID">
 <option value="1">Road</option>
 <option value="1">Cross-Country</option>
 <option value="1">Outdoor Track</option>
 </select>
</td>
    </tr>
    <tr>
      <td width="10" bgcolor="#CCCCCC">
      <td valign="middle" height="25" class="raceresutlstitle"
bgcolor="#CCCCCC">Race
        Time:</td>
      <td valign="middle" bgcolor="#CCCCCC"> <span class="hdtxt">HH
        <input type="text" name="RaceTimeHH" size="2" maxlength="2"
value="00">
        MM
        <input type="text" name="RaceTimeMM" size="2" maxlength="2"
value="23">
        SS
        <input type="text" name="RaceTimeSS" size="2" maxlength="2"
value="48">
        </span></td>
    </tr>
    <tr>
      <td width="10">
      <td valign="middle" height="25" class="raceresutlstitle">Race
Pace:</td>
      <td valign="middle"> <span class="hdtxt"> MM
        <input type="text" name="RacePaceMM" size="2" maxlength="2"
value="5">
        SS
        <input type="text" name="RacePaceSS" size="2" maxlength="2"
value="57">
        </span></td>
    </tr>
    <tr>
      <td width="10" bgcolor="#CCCCCC">
      <td valign="middle" height="25" class="raceresutlstitle"
bgcolor="#CCCCCC">#
        of Comp.:</td>
      <td valign="middle" bgcolor="#CCCCCC">
        <input type="text" name="RaceNumbComp" value="2000">
      </td>
    </tr>
    <tr>
      <td width="10" bgcolor="#ffffff">
      <td valign="middle" height="25" class="raceresutlstitle"
bgcolor="#ffffff">Race
        Place:</td>
      <td valign="middle" bgcolor="#ffffff">
        <input type="text" name="RacePlace" value="15">
      </td>
    </tr>
    <tr>
      <td width="10" bgcolor="#cccccc">
      <td valign="middle" height="25" class="raceresutlstitle"
bgcolor="#cccccc">Race
        City:</td>
      <td valign="middle" bgcolor="#cccccc">
 <select name="CityID">
 <option value="1">Somerville</option>
 <option value="1"></option>
 <option value="1">Boston</option>
 </select>
   </td>
    </tr>
    <tr>
      <td width="10" bgcolor="#ffffff">
      <td valign="middle" height="25" class="raceresutlstitle"
bgcolor="#ffffff">Race
        State:</td>
      <td valign="middle" bgcolor="#ffffff">

 <select name="StateID">
 <option value="1" if ($StateID == $StateID) print "selected">CA</option>
 </select>

      </td>
    </tr>
 <tr>
      <td width="10" bgcolor="#cccccc">
      <td valign="middle" height="25" class="raceresutlstitle"
bgcolor="#cccccc">PR:</td>
      <td valign="middle" bgcolor="#cccccc">
   <select name="PRID">
 <option value="1">No</option>
 <option value="1">Yes</option>
 </select>



      </td>
    </tr>
    <tr>
      <td width="10" bgcolor="#cccccc">
      <td valign="middle" height="25" class="raceresutlstitle"
bgcolor="#cccccc">Race
        Report:</td>
      <td valign="middle" bgcolor="#cccccc">
        <textarea name="RaceReport" cols="50" rows="3" value="">This is a
test</textarea>
      </td>
    </tr>
    <tr align="center">
      <td width="10">
      <td valign="middle" colspan="2" height="28">
        <input type="submit" name="Submit" value="Update Race">
      </td>
    </tr>
  </table>
</form>

</body>
</html>


I hope this clarifies the situation.




"Rick Emery" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> I'm trying to decipher:
> when I select the record to edit the drop-downlist has
> the first option as the value instead of what the corresponding
> StateID in
> the column reads. How can I correct this? The form to insert and
> edit have
> the below code and correctly insert the StateID
>
> What exactly is happening?  Run the script, do a View Source on the
> resulting page; show us the HTML generated.
>
> -----Original Message-----
> From: Steve Fitzgerald [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, March 26, 2002 5:22 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP-DB] Selecting Drop Down Value From DB to Edit
>
>
> I have the below code that populates a drop down list. The code will
> correctly insert the value $StateID into another a table. The problem I am
> running into is that when I select the record to edit the drop-downlist
has
> the first option as the value instead of what the corresponding StateID in
> the column reads. How can I correct this? The form to insert and edit have
> the below code and correctly insert the StateID. I tried to write and if
> statement to state that if the StateID were == to the StateID in he table
> then print selected, but I think I am missing something.
>
> Any suggestions?
>
> Thanks.
>
> <?php
>
> // populates state drop-down list
>
> $get_stateid_query = mysql_query("SELECT * FROM State INNER JOIN
RaceResults
> ON State.StateID WHERE RaceID='$RaceID'");
>
> echo " <select name=\"StateID\">\n";
>
> while ($myrow = mysql_fetch_array($get_stateid_query)) {
>
> echo ' <option
> value="'.$myrow["StateID"].'">'.$myrow["StateName"]."</option>\n";
> }
> echo " </select>\n";
> ?>
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to