Jump to content

SELECT BOX issues


my_r31_baby

Recommended Posts

This code works:
$sql = "SELECT * FROM odc_genre " ;
$result_genre = mysql_query( $sql ) or die ( 'Unable to execute query.' );
$num_genre = mysql_num_rows( $result_genre );
//echo $num_genre."<br>";
while ($row = mysql_fetch_assoc($result_genre)) { 
$gid = $row['odc_gen_id'];
$gname = $row['odc_gen_genname'];
?>
<option><?=$gname;?></option><br>
<?
}
RESULT
Kids
Family
Comedy
Romantic-Comedy
Comedy
Action
Sci-Fi
Drama
Thriller
Horror
Western


Here is my problem code:
<select name="genre">
  <option value="<?=$_POST['genre']?>">,<?=$_POST['genre']?></option>      
  <?
  while ($row = mysql_fetch_assoc($result_genre)) { 
    $gid = $row['odc_gen_id'];
    $gname = $row['odc_gen_genname'];
  ?>
  <option value="<?php echo $gid ; ?>"><?php echo $gname ; ?></option>
  <?
  };
?>


ANY Ideas??? The select box i get has nothing in it???
Link to comment
Share on other sites

[code]<select name="genre">
  <option value="<? echo $_POST['genre']; ?>"><? echo $_POST['genre']; ?></option>             
  <?
  while ($row = mysql_fetch_assoc($result_genre)) {
echo '<option value="' . $row['odc_gen_id'] . '">' . $row['odc_gen_genname'] . '</option>';
}
  ?>
</select>[/code]
Link to comment
Share on other sites

Slotted that little baby in and still getting the same result...  ???

Any other ideas?  ;)


Here is the full script: (might be easier putting into your own editor)
<?php
include("../db_connect.php");
include("functions.php");

session_start();
$u_pk = $_SESSION['u_pk'];

if (!session_is_registered('u_pk')) {
// Redirect to login page
header('Location: ../index.php');
exit;
} else {
// Load page
$num_problems = 1;

$sql = "SELECT * FROM odc_genre " ;
$result_genre = mysql_query( $sql ) or die ( 'Unable to execute query.' );
$num_genre = mysql_num_rows( $result_genre );
//echo $num_genre."<br>";
while ($row = mysql_fetch_assoc($result_genre)) { 
$gid = $row['odc_gen_id'];
$gname = $row['odc_gen_genname'];
?>
<option><?=$gname;?></option><br>
<?
}



$sql = "SELECT * FROM online_dvd_users WHERE odvdu_id = '$u_pk' " ;
$result = mysql_query( $sql ) or die ( 'Unable to execute query.' );
$num = mysql_num_rows( $result );

while ($row = mysql_fetch_assoc($result_genre)) { 
$fname = $row['odvdu_firstname'];
$lname = $row['odvdu_lastname'];
};




if($_POST['submitted']=="true") {

if($_POST['title']=="") {
  $error = "Title is missing";
  $num_problems = 1;
echo $error."<br>";
}
if($_POST['rating']=="") {
  $error = "Rating is missing";
  $num_problems = 1;
echo $error."<br>";
}
if($_POST['genre']=="") {
  $error = "Genre is missing";
  $num_problems = 1;
echo $error."<br>";
}

if ($num_problems == 0){
//Tests if a username already exists
$sql = "SELECT * FROM online_dvd_users WHERE odvdu_username = '$username' " ;
$result = mysql_query( $sql ) or die ( 'Unable to execute query.' ) ;
$num = mysql_num_rows( $result );
if ($num != 0){
$num_problems = 1;
echo $uname
?> already exists. Please try another username...
<?
}
}
}


?>

<!-- ------------------------------------ html starts here ----------------------------------------- -->

<head>
<link href="../css/style.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#6633FF">
<hr>
<div align="center"><h2>Add a new DVD</h2><br>
<strong>All <font color="#FF0000">*</font> items are mandatory.</strong><br>
  <form name="form1" method="post" action="dvd_add.php">
    <table>
<tr>
<td><div align="right">Local Ref #:</div></td>
<td><div align="left"><input type="text" name="local_ref"></div></td>
</tr>
<tr>
<td><div align="right">Title:</div></td>
<td><div align="left"><input type="text" name="title"></div></td>
<td><font color="#FF0000">*</font></td>
</tr>
<tr>
<td><div align="right">Rating:</div></td>
<td><div align="left">
<select name="rating">
<option value="<?=$_POST['rating']?>"><?=$_POST['rating']?></option>      
            <option value="G">G</option>
            <option value="PG">PG</option>
            <option value="M">M</option>
            <option value="M15+">M15+</option>
            <option value="MA">MA</option>
            <option value="MA15+">M15+</option>
            <option value="R18+">R18+</option>
            <option value="X">X</option>
          </select>
          </div></td>
<td><font color="#FF0000">*</font></td>
</tr>
<tr>
<td><div align="right">Genre:</div></td>
<td><div align="left">
<select name="genre">
  <option value="<? echo $_POST['genre']; ?>"><? echo $_POST['genre']; ?></option>             
  <?
  while ($row = mysql_fetch_assoc($result_genre)) {
echo '<option value="' . $row['odc_gen_id'] . '">' . $row['odc_gen_genname'] . '</option>';
}
  ?>
</select>
          </div></td>
<td><font color="#FF0000">*</font></td>
</tr>
<tr>
<td><div align="right">Comments:</div></td>
<td><div align="left"><input type="textbox" name="comments"></div></td>
</tr>
<tr>
<td><div align="right">DVD Cover File:</div></td>
<td><div align="left"><input type="text" name="file"></div></td>
</tr>
</table>
    <p>
      <input type="submit" name="reset" value="Reset">
      <input type="submit" name="submit" value="Submit">
      <input type="hidden" name="submitted" value="true">
    </p>
  </form>
</div>


</body>
<?
}
?>
Link to comment
Share on other sites

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.