Jump to content

Problem with getting update function to work?


magi

Recommended Posts

Hey guys. I'm using MySql with PHP. Anyways i have a drop down box that gets a list from the db and displays it. I made a button so when i click it. A table appears with all the info. And it has a input box to put a new value you. Then once i click another button. Its supposed to update the DB with the new info. Ive been trying for ages and i cant seem to get it. It says its successful. However nothing is being updated. Any help would be appreciated. Thanks in advance ;)

 

if(isset($_POST[edithero])){
	$get_hero_stuff=mysql_query("SELECT * FROM herodb WHERE Heroname='$hero_stuff[Heroname]'",$link ) or die(mysql_error());
	$hero_stuff=mysql_fetch_array($get_hero_stuff);	



                                //all my checks here		



	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 HeroID='',Heroname='$_POST[heroname]') WHERE Heroname='$hero_stuff[Heroname]'",$link ) or die(mysql_error());
		 $success[]="Hero successfully edited";			 			 			 
	} else{//print all the errors

 

                Heres my php and Mysql code  and i cant figure it out. Its coming out as successfully updated and none of my input checks seem to catch anything/I think it may be the query at the beginning because im not selecting the right thing or somehting? Im not quite sure ive tried everything :P And heres the part you need of the other code ;)

 

echo'<table class="profiletb1"><tr class="rowcap1"><td colspan="2">Hero : </td></tr>';
	echo'<tr><td class="admincellcen1" colspan="3">'.$hero_info[Heroname].'<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);

	echo'<table class="profiletb1"><tr class="rowcap1"><td colspan="2">Edit Hero</td></tr>';
	echo'<tr><td class="admincellleft1">Name, title:<span class="littletextred1"><br>Accept only numbers, letters, spaces, hypens and commas</span>';
	echo'<td class="admincellleft1">Current : '.$hero_info[Heroname].'<br><input class="inputp1" type="text" name="heroname" size="30" maxlength="40" value="'.$_POST[heroname].'"></td></tr>';

 

And theres the other part. Of course theres more things i want to add  in the update feature. But if i cant get it to update one thing then whats the point of having it there :P So any help would be appreciated. Thanks

Hi

 

Not sure it is the problem (as I would expect the OR DIE to catch it) is that you have an extra closing bracket after Heroname='$_POST[heroname]'

 

Also, you appear to do a select based on $hero_stuff[Heroname], and then put the data you grab into $hero_stuff, which suggests to me that you might have mixed up your variables. and meant to search for $_POST[Heroname] or something similar.

 

All the best

 

Keith

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.