SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Sydney
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Help Me: UPDATING a MySQL Table

    I have a MySQL table called authuser (in database ifdb) - it contains two fields: uname and level.

    When a user visits a page I want it to update their level so it equals 990.

    PHP Code:
     <?php $uname $check["uname"?>

    <?php

    mysql_connect
    ('localhost',username,password)or die("connect".mysql_error());
    mysql_select_db(ifdb)or die("connect".mysql_error());

    $UpdateRecords "UPDATE authuser SET level = 990, WHERE uname='$uname'";
    if (!
    $UpdateRecords) {
    echo (
    "<p>Error performing query: " .
    mysql_error() . "</p>");
    exit();
    }

        
    ?>
    When I visit this page, it does nothing!

    Thanks
    Last edited by wetfires; Jan 23, 2003 at 18:23.

  2. #2
    SitePoint Member
    Join Date
    Jun 2002
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Help Me: UPDATING a MySQL Table

    What do you mean "it does nothing"? According to your code you don't print ut "successfully changed" or something like that. So you should only get a blank page. And since you're not getting an error, something apparently is being set in the database, whether it's what you want, I can't tell you.

    Did you check if the value is set to 990 in MySQL?

  3. #3
    SitePoint Member
    Join Date
    Jun 2002
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Help Me: UPDATING a MySQL Table

    You had some errors in your query. This is the correct way.

    And what is username and password? Variables? In that case it should be $username and $password.

    PHP Code:
     <?php $uname $check["uname"?>

    <?php

    mysql_connect
    ('localhost',$username,$password)or die("connect".mysql_error());
    mysql_select_db(ifdb)or die("connect".mysql_error());

    $UpdateRecords "UPDATE authuser SET level = 990 WHERE uname='$uname'";
    if (!
    $UpdateRecords) {
    echo (
    "<p>Error performing query: " .
    mysql_error() . "</p>");
    exit();
    }

        
    ?>

  4. #4
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Sydney
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok - sorry.

    I get nothing meaning - the HTML below the PHP code does not appear. I also do not get any error messages.

    The level value on the table is also not updated.

  5. #5
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Sydney
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    dalmacija,

    Your code does the same thing as mine. The table is not updated.

    I can't see any difference between your code either (although I probably haven't looked hard enough). The username and password is just the username and password for MySQL I just got rid of them to post on here.

    Thanks
    Last edited by wetfires; Jan 23, 2003 at 19:08.

  6. #6
    SitePoint Member
    Join Date
    Jun 2002
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, first of all, your query was like this:

    $UpdateRecords = "UPDATE authuser SET level = 990, WHERE uname='$uname'";

    I think that comma after 990 shouldn't be there.

    About your username and password. If they are variables that you get from another file, it should be $username and $password. Otherwise, if you're just putting you username and password there directly, you must do it like this:

    mysql_connect('localhost','username','password')or die("connect".mysql_error());

  7. #7
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Sydney
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks.

    But it's still isn't working.

  8. #8
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Sydney
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is 'authuser' table on ifdb

    id uname passwd team level status lastlogin logincount
    18 ben tq23 Ungrouped 999 active 2003-01-24 09:39:06 10

    Now the code on y_part1_q22.php

    PHP Code:
    <?php

    mysql_connect
    ('localhost','user','pass')or die("connect".mysql_error());
    mysql_select_db(ifdb)or die("connect".mysql_error());

    $UpdateRecords "UPDATE authuser SET level = 990 WHERE uname='$username'";
    if (!
    $UpdateRecords) {
    echo (
    "<p>Error performing query: " .
    mysql_error() . "</p>");
    exit();
    }

        
    ?>
    Note: <?php echo($username) ?> on the page prints 'ben' fine with no problems.

    Thanks again!


  9. #9
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Sydney
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The level does not change from 999

  10. #10
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Sydney
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I changed it from $Updaterecords to $result and it still ain't working! Please help!

    PHP Code:
    <?php

    mysql_connect
    ('localhost','ifdbuser','ifdb19895')or die("connect".mysql_error());
    mysql_select_db(ifdb)or die("connect".mysql_error());

    $result "UPDATE authuser SET level = 990 WHERE uname='$username'";
    if (!
    $result) {
    echo (
    "<p>Error performing query: " .
    mysql_error() . "</p>");
    exit();
    }

        
    ?>

  11. #11
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Sydney
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm... i think i have to query the database first or something. can someone please help me! thanks

  12. #12
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Location
    Sydney
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah, it works finally!

    PHP Code:
    <?php

    mysql_connect
    ('localhost','ifdbuser','ifdb19895')or die("connect".mysql_error());
    mysql_select_db(ifdb)or die("connect".mysql_error());

    $query "UPDATE authuser SET level = 990 WHERE uname='$username'";
    $result mysql_query($query);
    print 
    "Worked";


    mysql_close();


        
    ?>


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
  •