$q = $db->query('INSERT INTO news (news_id, news_title, news_content, news_date, news_poster) VALUES (?,?,?,?,?)',
	                array($news_id, $news_title, $news_content, $news_date, $news_poster));

when i try executing that code in my script i get the error:

"DB Error: Contsraint Violation"

what does this mean? and what can i do to fix it?

    eyeofthestorm wrote:
    $q = $db->query('INSERT INTO news (news_id, news_title, news_content, news_date, news_poster) VALUES (?,?,?,?,?)',
    	                array($news_id, $news_title, $news_content, $news_date, $news_poster));

    when i try executing that code in my script i get the error:

    "DB Error: Contsraint Violation"

    what does this mean? and what can i do to fix it?

    you find all the answers in my signature

    😃 😃

      Are any of your fields in your table primary keys or unique. If so, you may be trying to insert a value into that field(s) that is already present.

      You might try adding the following after your insert:
      if ( DB::isError($q) ){
      die($q->getMessage());
      }

        OK, you have everything WE need to figure this out. But you're not posting it, probably because you aren't sure what to post.

        In this case, we'd need to see the statements that created this and all related tables. You likely either have a primary key or a foriegn key constraint. Or, if you're using a database like pgsql or firebird, then you might have actual check constraints or other issues.

        But we don't know what's causing this error, and the error message is pretty non-useful that's being thrown.

        So, got some more info?

          Write a Reply...