SitePoint Sponsor

User Tag List

Page 1 of 3 123 LastLast
Results 1 to 25 of 54

Thread: Code dosnt work

  1. #1
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Code dosnt work

    Hey people i got an update code to update the username u type in permission and opnick field but when i do it all it says record updated when it didnt even update here is my code:

    addop.php:

    <?
    include "theme.php";
    ?>
    <form action="addoppro.php" method="post">
    Username: <input type="text" name="username" value="<? echo $username; ?>"><br>
    Permission: <input type="text" name="permission" value="<? echo $permission; ?>"><br>
    Operator Nickname: <input type="text" name="opnick" value="<? echo $opnick; ?>"><br>
    <input type="Submit" value="Update">
    </form>
    addoppro:

    <?
    include "../db_connect.php";
    include "theme.php";

    $query = "UPDATE users SET username = '$username', permission = '$permission', opnick = '$opnick' WHERE username = '$username'";
    mysql_query($query);
    echo "Record Updated";
    ?>

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    I'm guessing that this would work if you didn' change the username field?
    the reason I say that is because if you update/ change the username from the form, the query will be invalid as it wont find the row with the new username.
    Either assign id numbers to the record and update where id=$id and use a hidden field in the form to pass the value or add a hidden field to hold the original username for the update script to use.

    Mike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    um do you think you could change the code so i type in the username to update the permissions and opnick field?

  4. #4
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    314
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sounds to me like register_globals is disabled on your domain.

    Try replacing $username with $_POST['username'] instead.

    Also, use something like this:

    PHP Code:
    <?
    include "../db_connect.php";
    include 
    "theme.php";

    $query "UPDATE users SET username = '".$_POST['username']."', permission = '".$_POST['permission']."', opnick = '".$_POST['opnick']."' WHERE username = '".$_POST['username']."'";
    mysql_query($query);
    echo 
    "Record Updated";
    ?>
    Does that help you?

  5. #5
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    still the same

  6. #6
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    314
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It should work. Sounds like a problem with your db or connection my friend
    Also, what's going on in theme.php?

    Peter

  7. #7
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nope deffenly dosnt work and the db connection works prefectly.

  8. #8
    SitePoint Zealot rain5017's Avatar
    Join Date
    Sep 2005
    Posts
    166
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <form action="addoppro.php" method="post">
    Username: <input type="text" name="newusername" value="<? echo $username?>"><br><input type="hidden" name="username" value="<? echo $username?>">
    Permission: <input type="text" name="newpermission" value="<? echo $permission?>"><br>
    Operator Nickname: <input type="text" name="newopnick" value="<? echo $opnick?>"><br>
    <input type="Submit" value="Update">
    </form>
    PHP Code:
    $query "UPDATE users SET username = '".$_POST['newusername']."', permission = '".$_POST['newpermission']."', opnick = '".$_POST['newopnick']."' WHERE username = '".$_POST['username']."'"
    mysql_query($query); 

  9. #9
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nope still didnt work

  10. #10
    SitePoint Zealot rain5017's Avatar
    Join Date
    Sep 2005
    Posts
    166
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Tidal Wave
    nope still didnt work
    Really??

    impossible

  11. #11
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    u sure its alirhgt cause when i type username i want tit to edit that username and change the permissions and opnick field to what i type in its ina table called users and the username is in a field called username and permissions is ina field called permissions and opnick is in a field called opnick

  12. #12
    SitePoint Zealot rain5017's Avatar
    Join Date
    Sep 2005
    Posts
    166
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Tidal Wave
    u sure its alirhgt cause when i type username i want tit to edit that username and change the permissions and opnick field to what i type in its ina table called users and the username is in a field called username and permissions is ina field called permissions and opnick is in a field called opnick
    if you want to do that the username is in a field called username and permissions is ina field called permissions and opnick is in a field called opnick,
    then you can't write "where username='$_POST[username]'",
    but you can try "where username='$username'"

  13. #13
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    now im getting a blank page this is my addoppro.php page:

    <?
    include "../db_connect.php";
    include "theme.php";
    $query = "UPDATE users SET username = '".$_POST['newusername']."', permission = '".$_POST['newpermission']."', opnick = '".$_POST['newopnick']."' "where username='$username'";
    mysql_query($query);
    echo "Record Updated";
    ?>

  14. #14
    SitePoint Zealot rain5017's Avatar
    Join Date
    Sep 2005
    Posts
    166
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Tidal Wave
    now im getting a blank page this is my addoppro.php page:
    Still can't work?

  15. #15
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    its just giving me a blank page

  16. #16
    SitePoint Zealot rain5017's Avatar
    Join Date
    Sep 2005
    Posts
    166
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the file addoppro.php is exists?

  17. #17
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes it does

  18. #18
    SitePoint Zealot rain5017's Avatar
    Join Date
    Sep 2005
    Posts
    166
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <?
    include "../db_connect.php";
    include "theme.php";
    $query = "UPDATE users SET username = '".$_POST['newusername']."', permission = '".$_POST['newpermission']."', opnick = '".$_POST['newopnick']."' "where username='$username'";
    mysql_query($query) or die(mysql_error());
    echo "Record Updated";
    ?>

    Post the mysql error report

  19. #19
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i put the code in and i get a blank page

  20. #20
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    Echo the query and omit the theme include....
    PHP Code:
    <? 
    include "../db_connect.php"
    #include "theme.php"; 
    $query "UPDATE users SET username = '".$_POST['newusername']."', permission = '".$_POST['newpermission']."', opnick = '".$_POST['newopnick']."' where username='$username'"
    echo 
    $query;
    mysql_query($query) or die(mysql_error());
    echo 
    "Record Updated"
    ?>
    what happens?

    EDIT: there was a syntax error in the query as well
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  21. #21
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    blank page

  22. #22
    SitePoint Zealot rain5017's Avatar
    Join Date
    Sep 2005
    Posts
    166
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <?
    include "../db_connect.php";
    #include "theme.php";
    $query = "UPDATE users SET username = '$_POST[newusername]', permission = '$_POST[newpermission]', opnick = '$_POST[newopnick]' where username='$_POST[username]'";
    echo $query;
    mysql_query($query) or die(mysql_error());
    echo "Record Updated";
    ?>

    try again

  23. #23
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    UPDATE users SET username = 'Ninechat', permission = 'member', opnick = 'None' where username=''Unknown column 'permission' in 'field list'

  24. #24
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    hmmm, OK try this just on its own so comment or hash out the rest of the scripts
    PHP Code:
    <?php
    echo '<pre>';
    print_r($_POST);
    echo 
    '</pre>';
    ?>
    That will print all the posted variables.
    What do you get?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  25. #25
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what do you mean?


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
  •