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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:48:43+00:00 2026-06-10T04:48:43+00:00

I am developing a small hobby application. Though I’ve worked with MySQL and PostgreSQL

  • 0

I am developing a small hobby application. Though I’ve worked with MySQL and PostgreSQL before, I’m more of a n00b here and would appreciate any help.

I have a table in my MySQL database called “TECH”. This table has two columns: “ID” (primary key) and “name” (name of the tech – not a key of any sort). Here are a couple of example rows:

+----+--------+
| ID |  name  |
+----+--------+
| 1  |  Python|
| 2  |  ASP   |
| 3  |  java  |
+----+--------+

Here is the code that creates TECH:

CREATE TABLE TECH (
        id      INT(5) ,
        name    VARCHAR(20),
        PRIMARY KEY (id)
);

I have developed an html form for the user to input a new technology into TECH. However, I would like to ensure that duplicate entries do not exist in TECH. For example, the user should not be allowed to enter “Python” to be assigned ID 4. Further, the user should also not be allowed to enter “pYthon” (or any variant of capitalization) at another ID.

Currently, I have the following code that does this (on the PHP side, not the MySQL side):

// I discovered that MySQL is not case sensitive with TECH.name
$rows = 0;
$result = $mysql_query("SELECT * FROM tech AS T WHERE T.name='python'");
while ($row = mysql_fetch_array($result)) {
    $rows += 1;
}

if ($rows != 0) {
    echo "'python' cannot be inserted as it already exists";
} else {
    // insertion code
}

Now, I know that the correct way to do this would be to constrain TECH.name to be UNIQUE by doing UNIQUE (name) and catching an “insert error” on the PHP side.
However, I have the following two questions regarding this process:

  1. Does defining the UNIQUE constraint maintain the apparent case-insensitivity addressed above?
  2. How do I go about catching exactly such an insert error on the PHP side?

I’d appreciate any help with this or any better ideas that anyone has.

  • 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-10T04:48:45+00:00Added an answer on June 10, 2026 at 4:48 am

    Changing the collation of the field to _ci or _cs would determine whether a unique key was caseinsensitive or casesensitive.

    As for catching the error, you should try using mysqli or PDO to run db queries: http://www.php.net/manual/en/pdo.exec.php

    You can catch a duplicate error entry with PDO like so:

    try
    {
        $dbh->exec($mySqlQuery);
        // insert was successful...
    } catch (PDOException $e) {
        if ($e->errorInfo[1]==1062) {
            // a 'duplicate' error occurred...
        } else {
            // a non 'duplicate error' occurred...
        }
    }
    

    Edit:

    If you’re not using PDO, this should work after your mysql_query:

    if (mysql_errno() == 1062)
    {
       // you have a duplicate error...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently developing a small application in WPF for us at work though I'm
I am developing an small application in a android. Before this i had done
Hi here i developing small application. In a subclass screen i have two buttons.
I am developing a small application and for that authentication is needed. That I'm
I'm developing a small application using Blend, basically what I have in my application
I'm developing a small application which requires adding user-defined values to a grid. Problem
Currently I am developing a small todo list manager and would like to use
I have question I'm developing small application to desktop in win Forms. I'm using
I'm currently developing a small REST API for my application. It works fine. There's
I am developing a small application that executes shell commands and displays the output

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.