SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2005
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face Edit script is not working

    I am working on a script that will edit users. First page displays all the users in a table, then the user clicks on the edit link next to the user they want to edit and it calls up the following code:

    PHP Code:
    <html>
    <head>
    <title>Edit Users</title>
    </head>
    <body>
    <h3>Edit Users</h3>
    <?php
    //connect to the database
      
    include("connect.php");
     
    if (isset(
    $_GET['User']) &&  isset($_GET['Password']))
      {
    //    echo '$MyKey<br>';
    //    echo '$User';
         
    $query "select * from users where MyKey = '$MyKey'";
         
    $result mysql_query($query);
         if (
    $result)
         {
            
    $row mysql_fetch_array($result);
    //        $MyKey=stripslashes($row['MyKey']);
            
    $User=stripslashes($row['User']);
            
    $passwd=stripslashes($row['Password']);
    ?>
          <form action="edit_user.php" method="POST">
          <table align="center">
          <tr>
          <td>Users Login<input type="hidden" name="MyKey" value="'.$MyKey.'"></td>
          <td><input type="text" name="User" value="'.$User.'"></td>
          </tr>
          <tr>
          <td>Password</td>
          <td><input type="text" name="Password" value="'.$passwd.'"></td>
          </tr>
          </table>
          </form>
    <?php
     
    }
     }
      else
      {
        
    $query "update users set User='$User', Password='$passwd'where (MyKey ='$MyKey')";
        
    $result mysql_query($query) or die ('Whoops did not work');
        if (
    mysql_affected_rows()==1)
        {
         echo 
    '<p align="center">Saved<br></p>';
        }
        else
        {
          echo 
    '<p align="center">Unable to Save User</p>';
        }
       }
    ?>
    <b><p align="center"><a href="display_user.php">Display Users</a></b></p>
    </body>
    </html>
    Apart from the heading Edit user and Saved I can't get this code to work at all. I have probably done something very silly but I just can't see it.

    If anyone can help I would really appreciate it.

    Many thanks

    Vonz

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    $query = "select * from users where MyKey = '$MyKey'";
    There's no $MyKey set in your code.

    $query = "update users set User='$User', Password='$passwd'where (MyKey ='$MyKey')";
    You set $User and $passwd in the if part of the if...else... so they don't exist here. You check if $_GET['User'] and $_GET['Password'] are set, but never use them for anything. You also need a space before the "where" in that query.

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2005
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I sort of understand what you are saying. I am not too sure about how to go about fixing all this are you able to talk me through it?

    many thanks
    Vonz


Bookmarks

Posting Permissions

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