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

  • Home
  • SEARCH
  • 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 522609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:22:19+00:00 2026-05-13T08:22:19+00:00

ive got a really weird problem. i have no clue why its not working.

  • 0

ive got a really weird problem. i have no clue why its not working. i create an user and get the id and insert a row based on that id in another table. the row gets inserted with that id but the other values however for that row are not inserted!

 $user_id = mysqli_insert_id($this->connection);

 $query = "INSERT INTO selections 
 (user_id, language_id, country_id, region_id, city_id, gender_id, age_id, category_id)
 VALUES ($user_id, 1, 1, 0, 0, 0, 20, 0)";

so the user_id gets inserted, but not the other values (they are all 0 in the table). i have really checked the columns and deleted all foreign keys to debug this problem. but i have no clue at all.

the columns are all INT. the weird part is sometime when i replace $user_id with a literal number it works, sometimes it doesnt. but the row is always created. and i have checked that $user_id is an integer.

i know this is a hard problem and that it can be caused of a lot of things, but i have tried to solve this tiny issue for 3 hours now. so would be great if someone just gave me something i could do to debug this problem.

UPDATE: even when i have set default values and just insert the first column (user_id) it doesnt work. every other field is 0. So weird!

| selections | CREATE TABLE `selections` (
  `user_id` int(11) NOT NULL,
  `language_id` int(11) NOT NULL DEFAULT '1',
  `country_id` int(11) NOT NULL DEFAULT '1',
  `region_id` int(11) NOT NULL DEFAULT '0',
  `city_id` int(11) NOT NULL DEFAULT '0',
  `gender_id` int(11) NOT NULL DEFAULT '0',
  `age_id` int(11) NOT NULL DEFAULT '0',
  `category_id` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |


  $query = "INSERT INTO selections
        (user_id)
        VALUES ('$user_id')";

the user_id shows 178 and other fields are 0:(

UPDATE:

It worked in the sql command line. but not in php. but mysqli generated no error and the row was indeed inserted but why are the other fields 0?

ANSWER: My fault. i had a jquery script that changed it back to 0 0 0 0 0 0 0. There’s a lot of AJAX on my page so it was tricky to find it…sorry my bad!

  • 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-13T08:22:20+00:00Added an answer on May 13, 2026 at 8:22 am

    When you run into situations like this, print the query to screen before it is executed:

    $query = "INSERT INTO ...";
    echo $query
    

    Try:

    $query = "INSERT INTO selections 
                (user_id, language_id, country_id, region_id, city_id, gender_id, age_id, category_id)
              VALUES 
                ({$user_id}, 1, 1, 0, 0, 0, 20, 0)";
    

    You need to wrap PHP variables in {} when referencing them in SQL string statements.

    Use Your DEFAULT Constraints


    If you have defaults then you don’t need to set the values in your INSERT statement:

    INSERT INTO selections 
      (user_id)
    VALUES 
      ({$user_id})
    

    Referencial Integrity


    You’re getting the last inserted id and using it in a subsequent insert into another table, but you don’t have a foreign key defined on the user_id column to ensure that the value going into that column actually exists in the other table. If you provide the name of the table & column you are getting for your last insert id, I’ll provide the ALTER TABLE statement.

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

Sidebar

Ask A Question

Stats

  • Questions 305k
  • Answers 305k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer ASP.net Tracing would be the one I'd go for. It'll… May 13, 2026 at 9:07 pm
  • Editorial Team
    Editorial Team added an answer No. Let's say you have INSERT followed by UPDATE on… May 13, 2026 at 9:07 pm
  • Editorial Team
    Editorial Team added an answer If MotorSteps = 49 then (50 - 49) / 50… May 13, 2026 at 9:07 pm

Related Questions

I've just recently setup a custom replication for my subscriber database, as described in
EDIT: Just to make things clear, this problem was caused by a typo in
I've got a really weird problem with ZF (at least for ZF newbie): I
I've got a really weird problem and i'm wondering if it's a visual's bug
Has anyone else run into this problem before? I've got a method that calls

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.