Jump to content


Photo

SELECT BOX issues


  • Please log in to reply
2 replies to this topic

#1 my_r31_baby

my_r31_baby
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 04 August 2006 - 09:03 PM

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???

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 04 August 2006 - 09:41 PM

<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>


#3 my_r31_baby

my_r31_baby
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 04 August 2006 - 09:53 PM

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>
<?
}
?>




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users