SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    adding User ID to mysql entry

    Hi guys

    When I add a entry I want the userid box to be filled with the Users Id

    At the moment it keeps showing 0 in the table when I submit

    Any help I would be thankful

    <?php
    $con = mysql_connect("localhost","notexper_two","three");
    if (!$con){ die('Could not connect: ' . mysql_error()); }
    mysql_select_db("notexper_one", $con);

    $sql = "INSERT INTO jobs
    (catergory, location, jobtitle, jobdescription, salary, jobstatus, company, firstname, surname, email, telephone, fax, userid)
    VALUES
    ('$_POST[catergory]','$_POST[location]','$_POST[jobtitle]','$_POST[jobdescription]','$_POST[salary]','$_POST[jobstatus]',
    '$_POST[company]','$_POST[firstname]','$_POST[surname]','$_POST[email]' ,'$_POST[telephone]' ,'$_POST[fax]', '".$_SESSION['username']."')";

    if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }
    echo "1 record added";
    mysql_close($con);
    ?>

  2. #2
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,561
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please clarify your problem. Is the new row being added to the database or not?

  3. #3
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes the new row is added every other field works fine apart from the last one
    userid

    say userid 62 adds a listing ithe userid box shows as 0

  4. #4
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,561
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What exact query is being run? To check, replace above code with this:

    PHP Code:
                                  <?php
    $con 
    mysql_connect("localhost","notexper_two","three");
    if (!
    $con){ die('Could not connect: ' mysql_error()); }
    mysql_select_db("notexper_one"$con);

    $sql "INSERT INTO jobs 
        (catergory, location, jobtitle, jobdescription, salary, jobstatus, company, firstname, surname, email, telephone, fax, userid)
        VALUES
        ('
    $_POST[catergory]','$_POST[location]','$_POST[jobtitle]','$_POST[jobdescription]','$_POST[salary]','$_POST[jobstatus]',
    '
    $_POST[company]','$_POST[firstname]','$_POST[surname]','$_POST[email]' ,'$_POST[telephone]' ,'$_POST[fax]', '".$_SESSION['username']."')";

    print 
    $sql;
    if (!
    mysql_query($sql,$con)) { die('Error: ' mysql_error()); }
    echo 
    "1 record added";
    mysql_close($con);
    ?>
    Let me know the result.

  5. #5
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    all that shows is the query im trying to do i want to know what is wrong in my script that is making the last field show as 0 everytime and not display the users id

  6. #6
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,561
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    all that shows is the query im trying to do i want to know what is wrong in my script that is making the last field show as 0 everytime and not display the users id
    We need to know what values are exactly being entered in the database. In particular, I need to know what value does $_SESSION['username'] hold. That's why I told you to post back the result.

  7. #7
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,561
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    also:
    Quote Originally Posted by dnbidder2005
    listing ithe userid box shows as 0
    Where is the userid box?


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
  •