SitePoint Sponsor

User Tag List

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

    What is this simple code?

    Hi people i got a table called users and fields like username, password and occupation and my site uses cookies and i was wondering what is the code to update the occupation part for that user?

  2. #2
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok this is the code i got now:
    when i fill it our it says it was updated then ichecked in hppmyadmin and wasnt updated at all

    oc.php file:

    <?
    include "theme.php";
    ?>
    <form name="form1" method="post" action="ocpro.php">

    Occupation: <input type="text" name="occupation"><br>

    <input type="submit" name="Submit" value="Submit">
    <input type="reset" name="reset" value="Reset Form">

    </form>
    Ocpro.php file:

    <?
    include "theme.php";
    include "db_check.php";
    $occupation = $_POST['occupation'];
    $username = $_POST['username'];

    $sql = "UPDATE users SET occupation='$occupation' WHERE username='$username'";

    if (!sql)
    {
    die ('unable to update users occupation: ' . mysql_error());
    }
    else
    {
    echo 'Users occupation updated';
    }
    ?>

  3. #3
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Your form script isn't passing the username to the Ocpro.php file !!

    Therefore you query is returning no results
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  4. #4
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i dont understand what code do i put it seems alright to me

  5. #5
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Your query is saying '.....WHERE username = $username'

    your php script is setting $username to equal $_POST['username']

    But your form isn't sending any data with the name 'username'

    Now do you see where the problem is ?
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  6. #6
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how would i fix it what would the code be?

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

  8. #8
    SitePoint Evangelist chiphunt1's Avatar
    Join Date
    Oct 2003
    Location
    louisville, ky
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    He said add the username in the form:

    <?
    include "theme.php";
    ?>
    <form name="form1" method="post" action="ocpro.php">

    Occupation: <input type="text" name="occupation"><br>
    Username: <input type="text" name="username"><br>
    <input type="submit" name="Submit" value="Submit">
    <input type="reset" name="reset" value="Reset Form">

    </form>

  9. #9
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by chiphunt1
    He said add the username in the form:

    <?
    include "theme.php";
    ?>
    <form name="form1" method="post" action="ocpro.php">

    Occupation: <input type="text" name="occupation"><br>
    Username: <input type="text" name="username"><br>
    <input type="submit" name="Submit" value="Submit">
    <input type="reset" name="reset" value="Reset Form">

    </form>
    Well I would guess that username would be stored in a variable by the time you get to the form, in which case I'd make it a hidden field and assign it to the variable $username.

    <?php
    echo '<input type="hidden" name="username" value="' . $username . '">';
    ?>

    Of course that will only work assuming you have defined the user in the variable $username berore getting to your form
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming


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
  •