connectiong two table

Discussion in 'PHP' started by tldmic, Feb 25, 2010.

  1. #1
    good day,
    being new in this php language,sometimes its very confusing even with little things, I have a code below, now i want to join two tables,
    with "id",

    clickon it
    for users table : id,username,password,

    for userlocation table : id,country,


    when i submit data,

    the results in database
    for users : id=1, and for userlocation id=0,

    i am using id to link the two tables, why doesn't it give me the same id value in both tables?

    thanks
    tldmic




    */
    function addNewUser($username, $password, $email){
    $time = time();
    /* If admin sign up, give admin user level */
    if(strcasecmp($username, ADMIN_NAME) == 0){
    $ulevel = ADMIN_LEVEL;
    }else{
    $ulevel = USER_LEVEL;
    }
    $q = "INSERT INTO ".TBL_USERS." VALUES (NULL,'$username', '$password', NULL, $ulevel, '$email', $time)";


    $fid = mysql_insert_id();
    $sql_insert= "insert into userlocation values('$fid','$_POST[country]')";
    mysql_query($sql_insert,$this->connection) or die(mysql_error());


    return mysql_query($q, $this->connection);
    }
     
    tldmic, Feb 25, 2010 IP
  2. hireme

    hireme Member

    Messages:
    58
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    45
    #2
    try changing this line:

    $q = "INSERT INTO ".TBL_USERS." VALUES (NULL,'$username', '$password', NULL, $ulevel, '$email', $time)";

    to:

    $q = "INSERT INTO ".TBL_USERS."('username','password','ulevel','email','time') VALUES ('$username', '$password', $ulevel, '$email', $time)";

    (or something like that :)
     
    hireme, Feb 25, 2010 IP