Page 1 of 1

Edit user form (need a help)

Posted: Mon Apr 16, 2012 6:01 pm
by viddz
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>" ;			
					     }
}
?> 

Re: Edit user form (need a help)

Posted: Tue Apr 17, 2012 9:29 pm
by Saman
It looks like you messed up with string manipulation in php. As a beginner I highly recommend you to use string concatenation with "." operator.

For example, you have used following code:

Code: Select all

$qry_edit = " UPDATE members SET login='$login', password='$password', type='$type' WHERE id='$id' ";
Change it to:

Code: Select all

$qry_edit = "UPDATE members SET login='" . $login "', password='" . $password . "', type='" . $type . "' WHERE id='" . $id . "'";
In this way it is crystal clear on what is happening.

Change your whole code in this way and let us know how it goes.

Good luck!

Re: Edit user form (need a help)

Posted: Thu Apr 19, 2012 9:15 am
by viddz
Problem was with parsing id. Thanku very much saman :D

Re: Edit user form (need a help)

Posted: Thu Apr 19, 2012 12:53 pm
by Saman
You are welcome!
Why don't you add a good Avatar (From User Control Panel), add some information about you such as location, etc... and write a little description about yourself under Member Introductions. So ROBOT.LK can get to know you better.

Re: Edit user form (need a help)

Posted: Fri Apr 20, 2012 9:56 pm
by viddz
Ha haa haa done. 8-)