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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:23:26+00:00 2026-06-07T00:23:26+00:00

This is my MySQL error. SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ” for

  • 0

This is my MySQL error.

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 2

I googled it and read something about it, bud I couldn’t understand.

How to solve it?

This is the main piece of addStudent.php:

require_once('../db.php');
$db = new DB();
if (isset($_POST['st_fname']) && isset($_POST['st_lname']) && isset($_POST['st_class']) && isset($_POST['st_grade']))
{
    $db->addStudent($_POST["st_fname"], $_POST["st_lname"], $_POST["st_class"], $_POST["st_grade"], $_POST["checkOlamp"]);
}

and this is a part of db.php:

public function addStudent($fname, $lname, $classnum, $grade, $olamp)
{
    $query = "INSERT INTO t_student (s_fname, s_lname, s_class, s_grade, s_olamp) VALUES('$fname', '$lname', '$classnum', '$grade', '$olamp');";
    $this->execute($query);
}

And the t_student has a filed as primary key which is auto increment.

  • db.php is something that I always use it instead of mysql_connection function in php, but I don’t know what it is exactly. I know something that called “PDO” is used there.
  • 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-07T00:23:28+00:00Added an answer on June 7, 2026 at 12:23 am

    It means that the values of some column in your table must be unique, and you are trying to insert a duplicate row.

    BTW, your function is vulnerable to SQL injection, you should always escape your data before including it in a SQL query.

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

Sidebar

Related Questions

I am getting duplicate entry error for primary key which is autoincrement field defined
I am receiving this mysql error and i don't know why. I am following
I dont know where my error is in this mysql query $sql = INSERT
i get this following error when i am trying to connect my localhost mysql
when i try to view the databases in mysql i get this error: ERROR
More specifically, I was using homebrew to install MySQL, and I got this error:
I am getting an error: Message: SQLSTATE[42000]: Syntax error or access violation: 1064 You
I get this error: Error: SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other
Is there a solution for this error? Is it happening because of the mySQL
My web page returns an error for the calls to mysql_connect() for this Mac

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.