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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:10:58+00:00 2026-05-26T10:10:58+00:00

new here and really green to programming, so go easy.. I discovered I have

  • 0

new here and really green to programming, so go easy..

I discovered I have an INSERT that is failing because of a duplicate record error. I figured it out by running the query in a MySQL console with literals, where err#1062 popped up.

What I want to understand is why mysql_error() or mysql_errno() didn’t catch this error in my PHP script.

Below is a generic setup of what I’ve done. I have a form that submits to a php file that calls data_insert()

function data_insert($var1, $var2, $var3, $var4){

    $db = db_connect();
    $query = "INSERT INTO exampletable (id, id_2, id_3, id_4) 
            VALUES ('$var1', '$var2', '$var3', '$var4')";

    $result = $db->query($query);
        if (!$result) 
            { 
            echo ('Database Error:' . mysql_error());
            } 
        else 
            {
            echo "Data added to db";
            }
}

The DB connection:

function db_connect()
{
    $result = new MySQLi('localhost', 'root', 'root', 'dbname');
    if (!$result)
        throw new Exception('Could not connect to database server');
    else
        return $result;
}

Result I’m getting is:

Database Error:

PHP echos “Database Error:” because the INSERT fails, but no subsequent MySQL error info is echoed. Honestly, I’m not exactly sure what I’m supposed to see, but through reading some other SO questions, I’ve double-checked my php.ini file for error handling and E_ALL and display_errors is set appropriately (although not sure if it matters in this case).

Is there something in my logic that I’m not understanding, like the scope of the link resource mysql_error() takes?

Thanks for your help, I’m hoping this is something embarrassingly obvious.

I know the above is missing XSS and security precautions and uniform exception handling. Baby steps though. It’s simplified here for discussion’s sake.

  • 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-26T10:10:58+00:00Added an answer on May 26, 2026 at 10:10 am

    You’re using mysqli (note the i) for your DB operations, but are calling mysql_error (no i). They’re two completely different interfaces, and do not share internal states at at all. DB handles/results from one are not usable in the other.

    Try mysqli_error() instead (note the I).

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

Sidebar

Related Questions

It is really annoying. Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new mainForm()); <-- pausing visual studio breaks here.
My colleague here argues that new programmers must learn ASP first, before they learn
Im new into that asp.net thing, but here goes. I got at ImageButton, and
I'm testing a new site, and I have a div with background-color: #bbf6bb; That
I am new here and got a question that is tricking me all day
New to posting here but got many really useful bits of help already. I
I'm getting an error here that says I haven't defined a method, but it
I have a new web app that is packaged as a WAR as part
Okay, I feel like I am missing something really simple here. I have an
I'm using Jquery(don't know if that's relevant), here's the regex: var re = new

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.