Edit user form (need a help)

Web programming topics
Post Reply
User avatar
viddz
Sergeant Major
Sergeant Major
Posts: 45
Joined: Fri Aug 26, 2011 6:06 am
Location: Colombo

Edit user form (need a help)

Post by viddz » 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>" ;			
					     }
}
?> 
User avatar
Saman
Lieutenant Colonel
Lieutenant Colonel
Posts: 828
Joined: Fri Jul 31, 2009 10:32 pm
Location: Mount Lavinia

Re: Edit user form (need a help)

Post by Saman » Tue Apr 17, 2012 9:29 pm

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!
User avatar
viddz
Sergeant Major
Sergeant Major
Posts: 45
Joined: Fri Aug 26, 2011 6:06 am
Location: Colombo

Re: Edit user form (need a help)

Post by viddz » Thu Apr 19, 2012 9:15 am

Problem was with parsing id. Thanku very much saman :D
User avatar
Saman
Lieutenant Colonel
Lieutenant Colonel
Posts: 828
Joined: Fri Jul 31, 2009 10:32 pm
Location: Mount Lavinia

Re: Edit user form (need a help)

Post by Saman » Thu Apr 19, 2012 12:53 pm

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.
User avatar
viddz
Sergeant Major
Sergeant Major
Posts: 45
Joined: Fri Aug 26, 2011 6:06 am
Location: Colombo

Re: Edit user form (need a help)

Post by viddz » Fri Apr 20, 2012 9:56 pm

Ha haa haa done. 8-)
Post Reply

Return to “Web programming”