Jump to content

Sticky drop down list - IF statement not evaluating as expected.


Vyr1s

Recommended Posts

Hey,

 

I have a page where a user is able to select an item from a drop down list and POST it to the same page.

Second time around when it generates the drop down it should default to the POST'd item and draw the rest of the page.

 

So far this works in other pages, and even below in the code when it needs to use another drop down.

 

Looks like it is currently always evaluating to true and the box cycles through quickly before sitting on the last option.

 

I'd imagine it's something to do with the passed values type but I can't seem to correct it.

 

<?php
//Checks if user is logged in
if($logged[id]) {
if($logged[ul]>=2){
echo "Edit Show<br /><br />";
$getshows = mysql_query("SELECT * FROM shows ORDER BY title");
echo "<form method='POST' action='index.php?pid=edit&show'><select name='sid'>";
while($show = mysql_fetch_array($getshows)){
echo "<option value=$show[sid]";
if($show[sid]==$_POST[sid]){
echo " selected='yes'";
}
echo ">$show[title]</option>";
}
echo "</select><input type='submit' value='Edit' /></form><br />";
if(isset($_GET[show])){
$query = mysql_fetch_array(mysql_query("SELECT title, genre FROM shows WHERE sid=$_POST[sid]"));
echo "<form method='POST' action='index.php?pid=edit&update'><table>
<tr><td>Title:</td><td><input type='text' value='$query[title]' name=title size=50 /></tr>
<tr><td>Genre</td><td><select name='genre'>";
$genres = mysql_query("SELECT * FROM genre ORDER BY gen ASC");
while ($genre = mysql_fetch_array($genres)){
echo "<option value='$genre[gid]'";
if($genre[gid]==$query[genre]){
echo " selected='yes'";
}
echo ">$genre[gen]</option>";
}
echo "</select></tr>
<tr><td>Season:</td><td><input type='hidden' value=$sid name='sid' /><input type='text' value='$query[season]' name=season /></tr>
<tr><td colspan=3><input type='submit' value='Modify' /></td></tr>
</table></form>";
}
if(isset($_GET[update])){
$title = htmlspecialchars($_POST[title]);
$season = htmlspecialchars($_POST[season]);
$genre = htmlspecialchars($_POST[genre]);
$update = mysql_query("UPDATE shows SET title='$title', season='$season', genre='$genre' WHERE sid='$sid'");
echo "Updated $title.";
}
}else{
echo "You do not have the required user access.";
}
}else
echo "You must be <a href='login.php'>logged in</a>!";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.