hi all,
i had a users page in which the Admin can add users.so while adding a user i am able to restrict the duplicate entries(same names).Those users will be displayed in a table, and there is a edit button, so Admin can edit users account(like active,inactive etc). here is my problem when i click on edit button a pop up wil open and i didnt change any thing and click update button, as i didnt change anything it should update but i am getting a popup as user already exist. so can any one...
Thanks in advance..
-----update.php-------------
<html>
<body>
<?php
$id=$_GET['f1'];
include 'connection.php';
$query="select * from users where userid='$id'";
mysql_error();
$result = mysql_query ($query) ;
$num=mysql_num_rows($result);
$i=0;
While($i < $num)
{
$userid=mysql_result($result,$i,"userid");
$sqlusername=mysql_result($result,$i,"username");
$password=mysql_result($result,$i,'password');
$role=mysql_result($result,$i,"role");
$status=mysql_result($result,$i,'status');
$allocatedmemory=mysql_result($result,$i,"allocatedmemory");
$arr_id=split("[{ }-]" ,$allocatedmemory);
$i++;
}
?>
<form action="update.php" method="post">
<div>
<center>
<table>
<tr>
<td style="color: navy;">Userid</td>
<td><input type="text" readonly="readonly" name="userid" value="<? echo $userid; ?>"></td>
</tr>
<tr>
<td style="color: navy;">Username</td>
<td><input type="text" name="username" id="txtname" value="<? echo $sqlusername; ?>"></td>
</tr>
<tr>
<td style="color: navy;">Password</td>
<td><input type="password" name="password" id="pwd" value="<? echo $password; ?>"></td>
</tr>
<tr>
<td style="color: navy;">Status:</td>
<td><select name="status">
<?php
if($status == 1)
{
echo '<option value="Active" selected="selected">Active</option>';
echo '<option value="Inactive">Inactive</option>';
}
else
{
echo '<option value="Inactive" selected="selected">Inactive</option>';
echo '<option value="Active">Active</option>';
}
?>
</select></td></tr>
<tr>
<td style="color: navy;">Allocatedmemory</td>
<td><input type="text" onkeypress="return isNumberKey(event)" id="am" name="allocatedmemory" value="<? echo $arr_id[0]; ?>"></td>
<td><select name="size">
<?php
if($arr_id[1]== "KB")
{
echo '<option value="MB">MB</option>';
echo '<option value="KB" selected="selected">KB</option>';
}
else
{
echo '<option value="MB" selected="selected">MB</option>';
echo '<option value="KB">KB</option>';
}?>
</select>
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="btn" value="Update" onclick="return (confirm('Are you sure you want to Update this?'),check())"/>
<input type="submit" name="btn" value="Delete" onclick="return (confirm('Are you sure you want to delete this?'))"/></td>
</tr>
</table>
</center>
</div>
</form>
</body>
</html>
<?php
$user=$sqlusername;
echo $user;
if(isset($_POST['btn']))
{
include 'connection.php';
if($_POST[btn]== 'Update')
{
$pname=$_POST['username'];
if($_POST[status] == 'Active')
$_POST[status] = 1;
else{
$_POST[status] = 0;
}
echo $pname;
if($user==$pname)
{
mysql_query("UPDATE users SET username = '$_POST[username]',password = '$_POST[password]', role = '1', status = $_POST[status], allocatedmemory = '$_POST[allocatedmemory] $_POST[size]' WHERE userid = '$_POST[userid]'");
echo "<script language='javascript'>
alert('User details updated');
</script>";
echo "<script language='javascript' type='text/javascript'>
window.close();
</script>";
}
else{
$query="select * from users where username='$pname'";
mysql_error();
$result=mysql_query($query);
$count=mysql_num_rows($result);
if($count==0)
{
mysql_query("UPDATE users SET username = '$_POST[username]',password = '$_POST[password]', role = '1', status = $_POST[status], allocatedmemory = '$_POST[allocatedmemory] $_POST[size]' WHERE userid = '$_POST[userid]'");
}
else
{
echo "<script language='javascript'>
alert('Username already exists');
</script>";
}
}
}
else if($_POST[btn] == 'Delete')
{
mysql_query("Delete from users where userid ='$_POST[userid]'");
echo "<script language='javascript'>
alert('Data Deleted');
</script>";
echo "<script language='javascript' type='text/javascript'>
window.close();
</script>";
}
}
?>