Edit user form (need a help)
Posted: Mon Apr 16, 2012 6:01 pm
Iam new to php and iam having some problems with my edit user php file. The problem is the query doesnt perform. PLs can some one help me with this code. Thanks in advance.
Code: Select all
<?php
session_start();
if(!isset($_SESSION['SESS_LOGIN']) || $_SESSION['SESS_TYPE'] !='admin')// if session variable "login" does not exist.
{
echo '<script language="javascript">';
echo 'alert("Please login as ADMINISTRATOR to edit a user");';
echo ' window.location.replace("login-form.php");';
echo '</script>';
//header("location:login-form.php"); // Re-direct to login-form.php
}
else
{
include("config.php");
$id = mysql_real_escape_string($_POST['id']);
$login = mysql_real_escape_string($_POST['login']);
$password = mysql_real_escape_string($_POST['password']);
$type = mysql_real_escape_string($_POST['type']);
$qry_edit = " UPDATE members SET login='$login', password='$password', type='$type' WHERE id='$id' ";
$count = mysql_query("SELECT COUNT(id) FROM members WHERE id='$id'");
if(mysql_num_rows($count)==1)
{
if($result=mysql_query($qry_edit))
//or die(mysql_error());
{
/*echo '<script language="javascript">';
echo 'alert("you have successfully edited one user !" );';
// echo 'window.setTimeout("window.location.replace('adduser.php');",20);';
//echo 'window.setTimeout("window.location.replace('adduser.php'),20");';
echo '</script>';*/
header("Location: view_all_user.php");
}
else
{
echo "<br><font color=red size=+1 >Problem in editing !</font>" ;
echo "ERROR - unable to save new username and password!<br>";
$SQLError = "SQL ERROR: ".mysql_errno().". ".mysql_error()."<BR><BR>";
echo "$SQLError";
mysql_close();
}
}
//echo "<br><font color=green size=+1 >you have successfully edited one user ! <br>[ username = $login ] </font>" ;
else
{
echo "<br><font color=red size=+1 >No id !</font>" ;
}
}
?>