SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Update not working...help needed..

    Hi all,

    I have a problem with my update code.after user log in,they can choose to update their details.This code can track user but it cannot do update.When they go to this page,all their particulars already there and they can just type again and click submit to update.

    The problem is user's particulars are not displayed,therefore they cant do the update.

    this is my code
    PHP Code:
    <?php
    mysql_connect
    ("localhost""ODBC""") or die(mysql_error()); 
    mysql_select_db("wms") or die(mysql_error()); 
    //checks cookies to make sure they are logged in 
    if(isset($_COOKIE['ID_my_site'])) 

    $username $_COOKIE['ID_my_site']; 
    $pass $_COOKIE['Key_my_site']; 
    $check mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); 
    while(
    $info mysql_fetch_array$check )) 

    //if the cookie has the wrong password, they are taken to the login page 
    if ($pass != $info['password']) 
    header("Location:http://localhost/projek/home.php"); 

    //otherwise they are shown the user area 
    else 


    $name $_GET[nama];
    $jawatan $_GET[jawatan];
    $no_kp $_GET[no_kp];
    $password $_GET[password];
        
    if(isset(
    $_GET['update']))
    {
        
    $sql "UPDATE users SET username = '$name', jawatan = '$jawatan', no_kp = '$no_kp', password =    '$password' WHERE username = '$username'";
        
        
    $result mysql_query($sql);
        
        echo 
    "Thank You!Information Updated.\n";
        
        
    $result=mysql_query("SELECT * FROM users WHERE username='$username'",$db);
        
        
    $myrow=mysql_fetch_array($result);

        
        }
    else if(
    $name $_GET[nama])
        {
        
    $result=mysql_query("SELECT * FROM users WHERE username ='$username'",$db);
        
        
    $myrow=mysql_fetch_array($result);
        }
        
        
    ?>
        
    <form method="get" action="<?php echo $PHP_SELF?>">
    <input type="hidden" name="id" value="<?php echo $myrow["id"]?>">
    Nama:<input type="text" name="nama" value=<?php echo $myrow["username"]?>><br>
    Jawatan:<input type="text" name="jawatan" value=<?php echo $myrow["jawatan"]?>><br>
    No Kad Pengenalan:<input type="text" name="no_kp" value=<?php echo $myrow["no_kp"]?>><br>
    Katalaluan:<input type="text" name="katalaluan" value=<?php echo $myrow["password"]?>><br>
    <input type="Submit" name="update" value="Kemaskini">
    </form>
    <?
        
    }
        
        }
        
        }
    ?>
    Can someone please help?

  2. #2
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    219
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $name $_GET[nama];
    $jawatan $_GET[jawatan];
    $no_kp $_GET[no_kp];
    $password $_GET[password]; 

    if these are not defined as constants you should be using:


    PHP Code:
    $name $_GET['nama'];
    $jawatan $_GET['jawatan'];
    $no_kp $_GET['no_kp'];
    $password $_GET['password']; 
    have you looked in the database - are the details blank?

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy

    No,my database have data.I've already correct my code as u show there but it still not working.

  4. #4
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    219
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Start putting some echo statement in there:

    Eg:
    PHP Code:
    echo $username;
    echo 
    $name;
    echo 
    $jawatan ;
    echo 
    $no_kp
    Also, get into the habit of checking vars before assigning them eg:

    PHP Code:
     $no_kp = isset($_GET[no_kp]) ? $_GET[no_kp] : ''

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the value of $username echoes back to me but the others no.
    the input box still blank.


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
  •