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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:29:32+00:00 2026-06-01T07:29:32+00:00

I am trying to insert a value in the database but when I open

  • 0

I am trying to insert a value in the database but when I open up the database the value is not inserted in the table. Now all of the code is correct in terms of no misspelling or anything like that but why isn’t it inserting a value in the DB table?

I just have to say that this field is not a primary key field, I am just testing this field which is a non primary key field, will it not insert a value in the db table if the primary key value is not inserted?

Below is the code:

<?php
    session_start();

    $username="xxx";
    $password="xxx";
    $database="mobile_app";

    mysql_connect('localhost',$username,$password);

    @mysql_select_db($database) or die( "Unable to select database");


    $sql="INSERT INTO Session (Course)
    VALUES
    ('$_POST[course]')";

    mysql_close();

    if (isset($_POST['course'])) {

    $_SESSION['course'] = $_POST['course'];

    }

    ?>
  • 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-01T07:29:33+00:00Added an answer on June 1, 2026 at 7:29 am

    You will need to add the Primary Key in there. You can’t add a row to the database without specifying the Primary Key, unless the Primary Key is auto-generated (an Identity).

    Edit: as Damien pointed out, you’ll need to add the following line after you define the $sql variable.

    mysql_query($sql)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to insert values in database and values are not being inserted,
I'm trying to insert a textbox value to a database table called site_list .
Trying to insert data in database from edittext in android but data is not
I am trying to insert an value as '019393' into a table with a
I'm trying to cache a price value using HttpRuntime.Cache.Insert(), but only appears to hold
I am trying to insert a value to a SQLite db, but everytime I
I am trying to insert data into a PostgreSQL database table using Python. I
I'm trying to insert into a database with the code below, I've tried everything
I am trying to insert data into my SQLite database. I have imported all
I'm trying to link sqlite3, create table and insert data but got this error:

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.