Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7717649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:57:18+00:00 2026-06-01T02:57:18+00:00

When registering my first user in table ‘users’ the id is the same value

  • 0

When registering my first user in table ‘users’ the id is the same value as user_id in the linking table,1, (language). However, when I register another user (id2 in users) the user_id in language is still 1. See SQL:

 CREATE TABLE `language` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `user_id` int(11) NOT NULL,
 `native` varchar(30) NOT NULL,
 `other` varchar(30) NOT NULL,
 `other_list` varchar(9) NOT NULL,
 `other_read` varchar(9) NOT NULL,
 `other_spokint` varchar(9) NOT NULL,
 `other_spokprod` varchar(9) NOT NULL,
 `other_writ` varchar(9) NOT NULL,
   PRIMARY KEY (`id`),
   KEY `user_id` (`user_id`)
 ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;


 CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `md5_id` varchar(200) NOT NULL,
  `full_name` tinytext CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
  `user_name` varchar(10) NOT NULL,
  `user_email` varchar(30) NOT NULL,
  `user_level` tinyint(4) NOT NULL DEFAULT '1',
  `pwd` varchar(220) NOT NULL,
  `nationality` varchar(30) NOT NULL,
  `department` varchar(20) NOT NULL,
  `birthday` date NOT NULL,
  `date` date NOT NULL DEFAULT '0000-00-00',
  `users_ip` varchar(200) NOT NULL,
  `activation_code` int(10) NOT NULL DEFAULT '0',
  `banned` int(1) NOT NULL,
  `ckey` varchar(200) NOT NULL,
  `ctime` varchar(220) NOT NULL,
  `approved` int(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

This is my PHP code:

if(empty($_SESSION['$user_id']))  { // user not logged in; redirect to somewhere else }
if (!empty($_POST['doLanguage']) && $_POST['doLanguage'] == 'Submit') 
{
$result = mysql_query("SELECT `id` FROM users WHERE `banned` = '0'") or 
die   (mysql_error());


list($id) = mysql_fetch_row($result);

session_start();
$_SESSION['user_id']= $id;

sql_insert = "INSERT into `language`
(`user_id`,`native`,`other`,`other_list`,`other_read`, `other_spokint`
,`other_spokprod`,`other_writ`  )
VALUES
('$id','$native','$other','$other_list','$other_read','$other_spokint',
'$other_spokprod','$other_writ') ";

mysql_query($sql_insert,$link) or die("Insertion Failed:" . mysql_error());     
}

header("Location: myaccount.php?id=' . $_SESSION[user_id] .'");
exit();

Would appreciate any help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T02:57:19+00:00Added an answer on June 1, 2026 at 2:57 am

    I think this is because your initial select query is selecting all users that are not banned

    So need to change the query to filter by the new user:

    "SELECT `id` FROM users WHERE `banned` = '0' and id=" . $_SESSION['$user_id'];
    

    The reason why the user_id field kept getting populated as 1 was because mysql_fetch_row was getting the first record which was user id 1.

    So if you filter it by the new user, mysql_fetch_row should get the id of the new user.

    EDIT

    I’m just looking at the code again, and it looks like you do not store the user id in php after you insert it, so your user_id for $_SESSION is null.

    So my above example will not work. Instead of the above query, use the following function to get the id of your newly created user. You call this function after you run your insert query. That function will get the new of your newly created user.

    mysql_insert_id()

    http://php.net/manual/en/function.mysql-insert-id.php

    EDIT 2

    Ok, since mysql_insert_id() didn’t work for you, maybe you can try the following. I just changed your select query to order by id desc.

    $result = mysql_query("SELECT `id` FROM users WHERE `banned` = '0' order by id desc")
    

    Just a note, this is probably not the best solution. But on a low traffic website it should be fine. To make the query a bit more accurate, you’d want to search for the user id based on a unique field like a username or email. This would make sure you get the correct id back.

    EDIT 3
    Here is an example of checking for the user’s email. This is just the mysql query, you’ll have to adjust this for php. Sorry I’m in class right now.

    "SELECT `id` FROM users WHERE `banned` = '0' and email='user@email.com' limit 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is registering components on castle windsor thread-safe? I.e., can multiple threads simultaneously register components
Currently I'm registering every user control separately in Web.config <pages validateRequest=false> <controls> <add tagPrefix=cc1
I am implementing IQueryCancelAutoPlay COM interface and registering it with the Running Objects Table
I have a typical form_for for registering user. But in the end I would
I have an extended UserProfile for registering new users. My user_created function connects to
I have an ASP.NET page with two instances of the same Web User Control
I have created a nice registration frontend app for registering new users for an
Am I doing something wrong? Why isn't the click event registering on the first
When registering an event via addEventListener on an element, then delete that element without
I found an example on registering DLLs, Registering an Assembly for COM Interop in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.