Jump to content

<select> Question


Guest Magisun05
 Share

Recommended Posts

Guest Magisun05

hey everyone. Im using PHP MySql with Html.Anyways the way i have it set up is that i have the drop down box with names populated from the database. Then i select one of the names to edit it and a form ( the edit form) is displayed. However when i click edit. The dropdown box goes to the first entry. Then at the bottom when i click edit it actually edits the one that is being shown (in this cazse the first item )Ex.Name: (dropdownbox)the one selected is named.. Please Edit(button)// form appears here. At that time the dropdown box goes to the first name which is Faust. Not please. EditNow when i click edit. it edits faust. not please like i would like it to.So how can i keep Please selected after i press edit ?

//display dropdown box for editing thing	if (($mine[m_post]=='Creations'||$mine[level]==1)&&(isset($_POST[EDIT_HERO]))){		echo'<table class="profiletb1"><tr class="rowcap1"><td colspan="2">Hero : </td></tr>';		echo'<tr><td class="admincellcen1" colspan="3"><select class="inputp" name="heromenu">';									$get_all_hname=mysql_query("SELECT * FROM herodb  ORDER BY HeroID ASC",$link ) or die(mysql_error());				while ($all_hname=mysql_fetch_array($get_all_hname))				{		 					echo"<option value='$all_hname[HeroID]'>$all_hname[Heroname]</option>";																			}				echo"</select></div></td></tr>";		echo'<tr><td class="admincellcen1" colspan="3"><div align="center"><input type="Submit" name="Edit_hero" value="Edit Hero"></div></td></tr></table>';						 }				//edit hero form	if (($mine[m_post]=='Creations'||$mine[level]==1)&&(isset($_POST[Edit_hero]))){		//display dropdown edit thing		if (isset($_POST[Edit_hero])){		echo'<table class="profiletb1"><tr class="rowcap1"><td colspan="2">Hero : </td></tr>';		echo'<tr><td class="admincellcen1" colspan="3"><select class="inputp" name="heromenu">';									$get_all_hname=mysql_query("SELECT * FROM herodb  ORDER BY HeroID ASC",$link ) or die(mysql_error());				while ($all_hname=mysql_fetch_array($get_all_hname))				{		 					echo"<option value='$all_hname[HeroID]'>$all_hname[Heroname]</option>";																			}				echo'</select></div></td></tr>';		echo'<tr><td class="admincellcen1" colspan="3"><div align="center"><input type="Submit" name="Edit_hero" value="Edit Hero"></div></td></tr></table>';						 }			$get_hero_info=mysql_query("SELECT * FROM herodb WHERE HeroID='$_POST[heromenu]'",$link ) or die(mysql_error());		$hero_info=mysql_fetch_array($get_hero_info);			//the edit form						}

And heres the Mysql part if its needed ( the insert )

//Editing a hero	if(isset($_POST[edithero])){				//check heroname for valid and duplicate				//other checks					if ($check1==1&&$check2==1&&$check3==1&&$check4==1&&$check5==1&&$check6==1&&$check7==1&&$check8==1&&$check9==1&&$check10==1&&$check11==1&&$check12==1&&$check13==1&&$check14==1&&$check15==1&&$check15==1) {			 $hero_edit_update=mysql_query("UPDATE herodb SET Heroname='$_POST[heroname]',Hatk='$_POST[heroatk]',Hdef='$_POST[herodef]',BAtk='$_POST[batk]',BDef='$_POST[bdef]',BHeal='$_POST[bcas]',BGold='$_POST[bgold]',BLumber='$_POST[blumber]',BIron='$_POST[biron]',BCrystal='$_POST[bcrystal]',BDiamond='$_POST[bdiamond]',BFood='$_POST[bfood]',BMage='$_POST[bmagic]',BSpy='$_POST[bspy]',HAup='$_POST[hatk]',HDup='$_POST[hdef]',herodes='$_POST[herodes]' WHERE HeroID='$hero_info[HeroID]'",$link ) or die(mysql_error());			 $success[]="Hero successfully edited";			 			 			 		} else{									//print all the errors					}				}

I THINK its an html issue. But if very well could be anything else. So any help is appreciated.Thx

Link to comment
Share on other sites

Correct me if I missunderstand, you are reloading the form, so the select list is being re-created from you MySQL database. You need to add some sort of test to see if the form has been submittted like

<input type="hidden" value="isSubmitted" />$isSubmitted = $_POST['isSubmitted']if($isSubmitted){echo "<option value='$var' selected='selected'>" . $var . "</option>";}

and then get the selection from the post data and set it as the selected choice. You will also have to write a test into your select output loop so you don't get duplicates.Hope this helps :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...