Jump to content
MakeWebGames

Help With Edit User


Seker

Recommended Posts

I had to re-do my staff edit user function because it just wasn't working for some reason.

Now, after re-doing it, it's still not working. It says "User Edited" but it just doesn't do anything.

Can anyone spot anything obvious?

 

function edit_user_form()
{
global $c, $h;

$user = abs((INT) $_POST['user']);

$d = mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us on u.userid=us.userid WHERE u.userid={$user}", $c);


if ($_POST['nusername'])
{
	$energy = 10 + $_POST['nlevel'] * 2;
       $nerve = 3 + $_POST['nlevel'] * 2;
       $hp = 50 + $_POST['nlevel'] * 50;

	mysql_query("UPDATE users SET username='{$_POST['nusername']}',level={$_POST['nlevel']},money={$_POST['nmoney']},crystals={$_POST['ncrystals']},energy=$energy,brave=$nerve,maxbrave=$nerve,maxenergy=$energy,hp=$hp,maxhp=$hp,hospital={$_POST['nhospital']},jail={$_POST['njail']},gang={$_POST['ngang']},donatordays={$_POST['ndonatordays']},display_pic='{$_POST['ndisplay_pic']}',bankmoney={$_POST['nbankmoney']} WHERE userid={$user}") or die(mysql_error());

	mysql_query("UPDATE userstats SET strength={$_POST['nstrength']},agility={$_POST['nagility']},guard={$_POST['nguard']},labour={$_POST['nlabour']},IQ={$_POST['nIQ']} WHERE userid={$user}") or die(mysql_error());

	print "User Edited!";
}
else
{

	$ue = mysql_fetch_array($d);
	if ($ue['display_pic'])
	{
		$pic = $ue['display_pic'];
	}
	else
	{
		$pic = "http://districtwars.net/pics/default.png";
	}

	print "
		<table width='590px' border='2'>
			<tr>
				<td align='center'>
					<form action='new_staff.php?action=edituserform' method='post' />
					Username: <input type='text' name='nusername' value='{$ue['username']}' /><br />
					Level: <input type='text' name='nlevel' value='{$ue['level']}' /><br />
					Gold: <input type='text' name='nmoney' value='{$ue['money']}' /><br />
					Tokens: <input type='text' name='ncrystals' value='{$ue['crystals']}' /><br />
					Hospital Time: <input type='text' name='nhospital' value='{$ue['hospital']}' /><br />
					Jail Time: <input type='text' name='njail' value='{$ue['jail']}' /><br />
					Gang ID: <input type='text' name='ngang' value='{$ue['gang']}' /><br />
					Donator Days: <input type='text' name='ndonatordays' value='{$ue['donatordays']}' /><br />
					Display Pic: <input type='text' name='ndisplay_pic' value='{$pic}' /><br />
					Gold Storage: <input type='text' name='nbankmoney' value='{$ue['bankmoney']}' /><br />
					Strength: <input type='text' name='nstrength' value='{$ue['strength']}' /><br />
					Agility: <input type='text' name='nagility' value='{$ue['agility']}' /><br />
					Guard: <input type='text' name='nguard' value='{$ue['guard']}' /><br />
					Labour: <input type='text' name='nlabour' value='{$ue['labour']}' /><br />
					IQ: <input type='text' name='nIQ' value='{$ue['IQ']}' /><br />
					<input type='submit' value='Edit User' /></form>
				</td>
			</tr>
		</table>";
}

}
Link to comment
Share on other sites

I could be wrong ... but where are you gathering the data for the nlevel, nomoney, ncrystals etc? Where are you declaring that they have to be set (isset)?

Well, as far as gathering the data, I left the default as is, and it collects and displays the information correctly. It's just, when you change it (The n* values are the new values you place in the form) it doesn't update.

Link to comment
Share on other sites

You are editing, right ... not creating a new one from what I can see. Could it have to do with the field not being defined in your table? Or it's a different type of field. int instead of decimal ... or vice versa? Just throwing some ideas that have snagged me in the past.

Link to comment
Share on other sites

where you have $user = abs((INT) $_POST['user']); try changing it to $_GET instead of POST, could be the reason why it's not updating, that i can think of. I dunno it does not look right to use $_POST at the end of the query part userid={$user}

usually it is $_GET. I maybe wrong i just have never used POST at the end.

Edited by lucky3809
Link to comment
Share on other sites

where you have $user = abs((INT) $_POST['user']); try changing it to $_GET instead of POST, could be the reason why it's not updating, that i can think of. I dunno it does not look right to use $_POST at the end of the query part userid={$user}

usually it is $_GET. I maybe wrong i just have never used POST at the end.

Well, it's coming from this, so I assumed POST would be right. Especially because I just tried changing it to GET and it came up with blank fields. :P

 

function edit_user_begin()
{
   global $ir, $c, $h, $userid;
   print 
           "<h3>Editing User</h3>
You can edit any aspect of this user. <br />
<form action='new_staff.php?action=edituserform' method='post'>
User: " . user_dropdown($c, 'user')
                   . "<br />
<input type='submit' value='Edit User' /></form>
OR enter a user ID to edit:
<form action='new_staff.php?action=edituserform' method='post'>
User: <input type='text' name='user' value='0' /><br />
<input type='submit' value='Edit User' /></form>";
}
Link to comment
Share on other sites

have you tried putting quotes around your fields in your queries that look like {$_POST['ndisplay_pic']} i dont know why but sometimes it has worked for others, there was a post not to long ago a user had the same problem but can't remember how it was solved unless I searched lol

Link to comment
Share on other sites

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.   Paste as plain text instead

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