SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jul 2003
    Location
    Bradford
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem updating (using methods from sitepoint book)

    Hi All!

    My first post under this nick i can't seem to retreive my old account

    right,

    I have the first edition of kevin yanks php book ... i've got most things running the way i want them to but for one thing when i use this script :

    http://www.sitepoint.com/article/319/1

    for restricting access i run into problems, i can create accounts but when i want to edit some details or insert them nothing happens. It says the tables have been edited but in fact they have not. heres the script i am using:


    <?php

    if (isset($_POST['submit'])):
    // The author's details have
    // been updated.

    $email = $_POST['email'];
    $userid = $_POST['id'];
    $sql = "UPDATE user SET
    userid='$userid',
    email='$_POST[$email]'
    WHERE id='$uid'";

    if (@mysql_query($sql)) {
    echo('<p>Author details updated.</p>');
    } else {
    echo('<p>Error updating author details: ' .
    mysql_error() . '</p>');
    }

    ?>



    <?php
    else: // Allow the user to edit the author
    // with ID=$id

    $id = $_GET['id'];
    $author=@mysql_query("SELECT userid, email
    FROM user
    WHERE userid='$uid'");
    if (!$author) {
    die('<p>Error fetching author details: ' .
    mysql_error() . '</p>');
    }

    $author = mysql_fetch_array($author);

    $userid = $author['userid'];
    $email = $author['email'];


    // Convert special characters for safe use
    // as HTML attributes.
    $userid = htmlspecialchars($userid);
    $email = htmlspecialchars($email);
    ?>
    </p>
    <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
    <table align=center bgcolor=#AAAAAA border=0 cellspacing=1 cellpadding=6>
    <tr>
    <td align=center bgcolor=#993333 colspan=2><font size=2 face=verdana color=FFFFFF><b>Edit User details</b>
    </td></tr>
    <tr><td bgcolor=EEEEEE><font size=2 face=verdana>Username/td><td bgcolor=EEEEEE> <input type="text" name="username" value="<?=$username?>" size="20" maxlength="255" />

    </td></tr>
    <td bgcolor=EEEEEE><font size=2 face=verdana>Users Email: </td><td bgcolor=EEEEEE><input type="text" name="email" value="<?=$email?>" size="20" maxlength="255" />
    </td></tr>
    <tr><td bgcolor=EEEEEE colspan=2>

    <input type="submit" name="submit" value="Edit Users Details" /></p>
    </td></tr></table>
    </form>

    <?php endif; ?>

    can anybody help?

  2. #2
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    I think your query is failing. Remove the @ infront of mysql_query() and you'll get the error messages.

    What is wrong with your query is that you're probably missing the userid. The userid isn't sent along with the form. You need a (hidden) field in your form and send the id along with it.

    If you want to see what the $_POST array contains, add the following part in your update section
    PHP Code:
    echo '<pre>';
    print_r($_POST);
    echo 
    '<pre>'
    If anything is unclear, let me know and I'll explain further.

    -Helge

  3. #3
    SitePoint Member
    Join Date
    Jul 2003
    Location
    Bradford
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I shall try this when i get home thanks for your help

  4. #4
    SitePoint Member
    Join Date
    Jul 2003
    Location
    Bradford
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi i've removed them @ signs, now when i update i get this:

    Author details updated.

    then i go and look at the table and nothing has changed. The email field stays blank or any other field i try edit. When i use this command without the login script through my cms i made it updates but doesnt using the password script with it.
    http://www.findyourhost.co.uk/
    Find Your Host - UK Webhosting Directory
    We'll help you Find Your Host!

  5. #5
    SitePoint Member
    Join Date
    Jul 2003
    Location
    Bradford
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    fixed it simple error in the update command i was putting id when it should of been userid ... sheesh need to examine my code in future lol
    http://www.findyourhost.co.uk/
    Find Your Host - UK Webhosting Directory
    We'll help you Find Your Host!

  6. #6
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by FYH
    sheesh need to examine my code in future lol
    We all make those mistakes sometimes.

    Glad you got it working.

    -Helge


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
  •