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 929851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:14:16+00:00 2026-05-15T20:14:16+00:00

ok im makeing a simple database for my example, there is users data and

  • 0

ok im makeing a simple database for my example, there is users data and the user company’s data .

CREATE TABLE `users` (
  `UID` INT(25) NOT NULL AUTO_INCREMENT ,
  `username` VARCHAR(60) NOT NULL ,
  `password` VARCHAR(100) NOT NULL ,
  `ownername` VARCHAR(150) NOT NULL ,
  `userstatus` TINYINT(1) NOT NULL ,
  `userregistertime` DATETIME NOT NULL ,
  `userlastonline` DATETIME NOT NULL ,
  PRIMARY KEY (`UID`) ,
  INDEX `username` (`username` ASC) )
  ENGINE = InnoDB
  DEFAULT CHARACTER SET = utf8;

CREATE TABLE `company` (
  `CID` INT(25) NOT NULL AUTO_INCREMENT ,
  `UID` INT(25) NOT NULL ,
  `companyname` VARCHAR(60) NOT NULL ,
  `companyaddress` VARCHAR(255) NOT NULL ,
  `companyemail` VARCHAR(255) NULL DEFAULT NULL ,
  `companyphone` VARCHAR(20) NOT NULL ,
  `companyimage` VARCHAR(255) NULL DEFAULT NULL ,
  `companyyahoo` VARCHAR(255) NULL DEFAULT NULL ,
  `companytwitter` VARCHAR(255) NULL DEFAULT NULL ,
  `companykaskus` VARCHAR(255) NULL DEFAULT NULL ,
  `companyfacebook` VARCHAR(255) NULL DEFAULT NULL ,
  `companytype` TINYINT(1) NOT NULL DEFAULT '0' ,
  `companystatus` TEXT NULL DEFAULT NULL ,
  `companytemplate` TEXT NULL DEFAULT NULL ,
  `companyintroduction` TEXT NULL DEFAULT NULL ,
  `partnership` TINYINT(1) NOT NULL DEFAULT '0' ,
  PRIMARY KEY (`CID`) ,
  INDEX `ownername` (`UID` ASC) ,
  INDEX `companyname` (`companyname` ASC) ,
  CONSTRAINT `ownernamecompany`
    FOREIGN KEY (`UID` )
    REFERENCES `users` (`UID` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;

1.why after i insert data to the users table ( uid is auto increment ) it doesnt update my company UID table ?

if you have php knowledge please see how im inserting it.

$RegisterInsert1 = $dbConnect->prepare("INSERT INTO users (
`username`, `password`, `ownername`, `userregistertime`, `userlastonline`) VALUES (
:username, :password, :ownername, :userregistertime, :userlastonline)");
$RegisterInsert1->execute($RegisterData1); 

as you see, i get, UID = 1 ( auto ) then username,pasword,ownername,etc inserted on user table. but somehow my company UID is not updated. it should be UID = 1 then the rest CID ( auto ) companyname null, etc null.

2.am i right defining a foreign key usage for?

3.please give me the best example of inserting users data + company data with the right usage from the right usage of foreign.

how im doing it right now

// INSERT USERS DB
$RegisterInsert1 = $dbConnect->prepare("INSERT INTO users (
`username`, `password`, `ownername`, `userregistertime`, `userlastonline`) VALUES (
:username, :password, :ownername, :userregistertime, :userlastonline)");
$RegisterInsert1->execute($RegisterData1);

// GET USERS GIVEN AUTO GENERATED UID
// QUESTION ? THIS one should be automated by foreign useage ?
$GetUid = $dbConnect->prepare("SELECT UID FROM users WHERE username = :username");
$GetUid->execute($RegisterData3);
$UserID = $GetUid->fetch();
$RegisterData2['UID'] = $UserID;

// INSERT COMPANY INFO + UID
$RegisterInsert2 = $dbConnect->prepare("INSERT INTO company (
`UID`,`companyphone`,`partnership`) VALUES (
:UID, :companyphone, :partnership)");
$RegisterInsert2->execute($RegisterData2);
  • 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-05-15T20:14:16+00:00Added an answer on May 15, 2026 at 8:14 pm

    why after i insert data to the users
    table ( uid is auto increment ) it
    doesnt update my company UID table ?

    SQL does not support multiple assignment, you need to do this procedurally. You need to use (at least) one INSERT statement per table.

    1. INSERT INTO users which
      auto-generates the UID value(s);
    2. Capture auto-generated value(s) for
      UID;
    3. INSERT INTO users supplying the
      captured UID value(s).

    FWIW SQL Server 2008 makes this easy with an OUTPUT keyword i.e. the auto-generated values can be captured (to a staging temp table) within the INSERT statement. In MS Access, you could create a VIEW with a JOIN between the two tables then INSERT INTO the VIEW and the auto-generate value would appear automatically in both tables (only worked for a two-table VIEW). I don’t know if mySQL has similar features.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a very simple application to display the contents of a database table
I am making simple connection between two table - first one called users has
Put simply about Table Data Gateway (TDG) implementation: you create separate TDG class that
I am making a very simple database (mysql) with essentially two types of data,
I'm making a simple task list app, and I'm using a database to hold
Making a simple application, so when the user logs out of Windows, it of
I'm making a simple interface that will allow a user to modify pieces of
I am using Excel to store data kind of as a relational database for
I'm making a simple high scores database for an iPhone game using Amazon's SimpleDB
I am making a web page which create user and a page from which

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.