Edit user (need a help)
Results 1 to 7 of 7

Thread: Edit user (need a help)

  1. #1
    Member
    Join Date
    Apr 2012
    Posts
    92

    Edit user (need a help)

    Guys Iam new to php. When Iam going to edit users using following php code. I always get "No ID !" msg. Pls help me to correct this problem.

    PHP Code:

    <?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(
    $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 added one user ! <br>[ username = $login ] </font>" ;
            
    else
                {
                echo 
    "<br><font color=red size=+1 >No id !</font>" ;            
                                 }
    }

    ?>

  2. #2
    Senior Member anoopmail's Avatar
    Join Date
    May 2005
    Location
    Hell
    Posts
    241
    Replace if($count==1) with
    PHP Code:
     if(mysql_num_rows($count)==1

  3. #3
    Member
    Join Date
    Apr 2012
    Posts
    92
    This is the edit user form
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Edit user</title>



    <script type="text/javascript">

      function validateForm(){
          with (document.edituserForm)
          
      {
        if(login.value == "") {
          alert("Error: login cannot be blank!");
          login.focus();
          return false;
        }
         if(login.value.length < 4) {
            alert("Error:Login must contain at least four characters!");
            login.focus();
            return false;
          
          }
        
        re = /^\w+$/;
        if(!re.test(login.value)) {
          alert("Error: login must contain only letters, numbers and underscores!");
          login.focus();
          return false;
        }

        if(password.value == "" ) {
        alert("Error: Password field cannot be blank !");
          password.focus();
          return false;
        }
          if(password.value.length < 4) {
            alert("Error: Password must contain at least four characters!");
            password.focus();
            return false;
          }
                
              if(!re.test(password.value)) {
          alert("Error: Password must contain only letters, numbers and underscores!");
          password.focus();
          return false;
          
          }

         
        
        else 
          
           // alert("You have added a new user : " + login.value);
        return true;
      
      }}
    </script>

    <link href="table.css" rel="stylesheet" type="text/css" media="screen" />

    </head>

    <body>
    <?php  $id $_GET[id]; ?>

    <form ACTION="edit_user_save.php" name="edituserForm" id="edituserForm" METHOD="POST" align="center" onsubmit="return validateForm()" >

    <input type="hidden" name="id" value="$id" />
    <div align="center"><center>
      <table width="436" id="table">
        <tr>
          <td width="214">username</td>
          <td width="254"><input name="login" maxlength="10" id="login" /></td>
          </tr>
        <tr>
          <td>password</td>
          <td><input type="text" id="password" name="password" maxlength="10" /></td>
          </tr>
        <tr>
          <td>Select user type :</td>
          <td><select  name="type" id="type">
            <option value="admin"> Admin </option>
            <option value="labassistant"> Lab Assistant </option>
            <option value="storekeeper"> Store Keeper </option>
            </select></td>
          </tr>
        
        <tr>
          <td></td>
          <td><input type="submit" name="button" id="button" value="save"/></td>
          </tr>
        </table>
    </center></div>
          
          </form>
    </body>
    </html>

  4. #4
    Member
    Join Date
    Apr 2012
    Posts
    92
    @anoopmail, thanks.
    now the error is disappeared. But when i click edit and do some changes. They dont happen(query doesnt perform).

  5. #5
    Senior Member anoopmail's Avatar
    Join Date
    May 2005
    Location
    Hell
    Posts
    241
    comment header("Location: view_all_user.php"); and start debugging to confirm it enters the if condition just after if(mysql_num_rows($count)==1)

  6. #6
    Member
    Join Date
    Apr 2012
    Posts
    92
    ya, it enter the if condition. But no change occur.

  7. #7
    Senior Member anoopmail's Avatar
    Join Date
    May 2005
    Location
    Hell
    Posts
    241
    print the query nd check it forms as you expect. Post it over here u still can't find.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •