Jump to content

Recommended Posts

Hi there.

I have a from so the administrator can edit records.

The form is populated with the current record information.

There is a drop down menu which is populated from the table "shows"

The user can select an option, click submit, and the record is changed.

 

It all works, except if the user chooses the first option from the drop down menu.

 

I have tried changing which option is listed first, I have tried changing the text in the database (thinking maybe there were some "illegal" characters), but nothing.

 

If I do a simple echo of each record in the table, everything shows up normal, so it is definitely something to do with the drop down menu or how I am pulling information into it.

 

If you go to www.workjuice.net/cms/all.php you can click on "edit" to get to the form. From the form, click "Update" and you will see a list of the "new" info that would be inserted into the table. You'll see, that for all options, except the first, chosen from the drop down, an id number is returned. For some reason, the first option will not return an id. And don't worry, no data will actually be changed, I disabled that part.

 

Thanks!!

 

Here is the code for the whole page:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Edit An Epsiode</title>
</head>

<body>
<?php
if (!$_POST['submit'])
{
     // check for record ID
     if ((!isset($_GET['id']) || trim($_GET['id']) == '')) 
     { 
         die('Missing record ID!'); 
     }

    // open database connection
   include '../connections/medianstrip.php';


    // generate and execute query
    $id = $_GET['id'];
$this_show = $_GET['show_name'];
$this_show_id = $_GET['this_show_id'];


    $query = "SELECT perf_date, ep_title, ep_summary, guests FROM previouslies WHERE id = '$id'";
    $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());


    // if a result is returned
    if (mysql_num_rows($result) > 0)
    {
        // turn it into an object
        $row = mysql_fetch_object($result);
	//$this_show_id = $row->show_id;
}
}
?>

<h3> Edit Epsiode </h3>
<table width="600" cellspacing="5" cellpadding="5"  bgcolor="#FFE8B7">
<form action="insertEditEpisode.php"  method="POST">
<input type="hidden" name="id"  value="<?php echo $id; ?>">

<tr>
    <td valign="top"><h2>Performance Date </h2></td>
    <td>
      <input size="50" maxlength="250" type="text" name="perf_date" 
value="<?php echo $row->perf_date; ?>">
    </td>
</tr>


<tr>
    <td valign="top"><h2>Episode Title </h2></td>
    <td>
      <input size="50" maxlength="250" type="text" name="ep_title" 
value="<?php echo $row->ep_title; ?>">
    </td>
</tr>
<tr>
    <td valign="top"><h2>Summary</h2></td>
    <td>
      <textarea name="ep_summary" cols="37" rows="5"><?php echo $row->ep_summary; ?></textarea>
    </td>
</tr>
<tr>
    <td valign="top"><h2>Guest Stars </h2></td>
    <td>
      <input size="50" maxlength="250" type="text" name="guests" 
value="<?php echo $guests; ?>">
    </td>
</tr>
<tr>
    <td valign="top"><h2>Show</h2></td>
    <td>
<?php
/////// HERE'S WHERE I THINK THE PROBLEM BEGINS /////////////

$query = "SELECT show_id, show_name FROM shows ORDER BY show_name ASC";
    $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
$options="";

while ($row=mysql_fetch_array($result)) {

   
    $show_name=$row["show_name"];
 $show_id=$row["show_id"];
    $options.="<OPTION VALUE=\"$show_id\">".$show_name;

} 
?>
<input type="text" name="show_id"  value="<?php echo $this_show_id; ?>">

     <select  maxlength="60" type="text" name="new_show_name" class="formText">
	<option value="<?php echo $this_show_id; ?>"><?php echo $this_show; ?></option>
	<option value="<?php echo $options; ?>"></option>
    
      </select>

    </td>
</tr>
<tr>
    <td align="" colspan=2>
      <input type="Submit" name="submit" value="Update">
    </td>
</tr>
</form>
</table>

</body>
</html>

Your OPTION tags are all messed up within the drop down list.

 

Give this a go.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Edit An Epsiode</title>
</head>

<body>
<?php
if (!$_POST['submit'])
{
     // check for record ID
     if ((!isset($_GET['id']) || trim($_GET['id']) == '')) 
     { 
         die('Missing record ID!'); 
     }

    // open database connection
   include '../connections/medianstrip.php';


    // generate and execute query
    $id = $_GET['id'];
$this_show = $_GET['show_name'];
$this_show_id = $_GET['this_show_id'];


    $query = "SELECT perf_date, ep_title, ep_summary, guests FROM previouslies WHERE id = '$id'";
    $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());


    // if a result is returned
    if (mysql_num_rows($result) > 0)
    {
        // turn it into an object
        $row = mysql_fetch_object($result);
	//$this_show_id = $row->show_id;
}
}
?>

<h3> Edit Epsiode </h3>
<table width="600" cellspacing="5" cellpadding="5"  bgcolor="#FFE8B7">
<form action="insertEditEpisode.php"  method="POST">
<input type="hidden" name="id"  value="<?php echo $id; ?>">

<tr>
    <td valign="top"><h2>Performance Date </h2></td>
    <td>
      <input size="50" maxlength="250" type="text" name="perf_date" 
value="<?php echo $row->perf_date; ?>">
    </td>
</tr>


<tr>
    <td valign="top"><h2>Episode Title </h2></td>
    <td>
      <input size="50" maxlength="250" type="text" name="ep_title" 
value="<?php echo $row->ep_title; ?>">
    </td>
</tr>
<tr>
    <td valign="top"><h2>Summary</h2></td>
    <td>
      <textarea name="ep_summary" cols="37" rows="5"><?php echo $row->ep_summary; ?></textarea>
    </td>
</tr>
<tr>
    <td valign="top"><h2>Guest Stars </h2></td>
    <td>
      <input size="50" maxlength="250" type="text" name="guests" 
value="<?php echo $guests; ?>">
    </td>
</tr>
<tr>
    <td valign="top"><h2>Show</h2></td>
    <td>
<?php
/////// HERE'S WHERE I THINK THE PROBLEM BEGINS /////////////

$query = "SELECT show_id, show_name FROM shows WHERE show_id != $this_show_id ORDER BY show_name ASC";
    $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
$options="";

while ($row=mysql_fetch_array($result)) {

   
    $show_name=$row["show_name"];
 $show_id=$row["show_id"];
    $options.="<option value=\"$show_id\">$show_name</option>";

} 
?>
<input type="text" name="show_id"  value="<?php echo $this_show_id; ?>">

     <select  maxlength="60" type="text" name="new_show_name" class="formText">
	<option value="<?php echo $this_show_id; ?>"><?php echo $this_show; ?></option>
	<?php echo $options; ?>
    
      </select>

    </td>
</tr>
<tr>
    <td align="" colspan=2>
      <input type="Submit" name="submit" value="Update">
    </td>
</tr>
</form>
</table>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.