1

I am working on a MySQL table which have a primary key on two fields. I would like to retrieve primary key error during an insertion with PHP. please help me...My php code does not show any error.. but it is not inserting the values in the table if it already contains those values..

 mysql_query("insert into external values(1111,'xxx','yyy')");

for my table both first and second column together act as primary key.if my table already contains the entry like 1111 xxx zzz. this code will not insert these values. but there is no error msg too..

Thanks in advance!

user3763227
  • 292
  • 2
  • 15
  • You can not have 2 primary key defined in one table. – prava Jun 22 '14 at 05:28
  • 1
    show the code you try – Haim Evgi Jun 22 '14 at 05:31
  • You need to show your schema definition, use the [`SHOW CREATE TABLE`](http://dev.mysql.com/doc/refman/5.0/en/show-create-table.html) statement, and then your PHP code that you are using. "Please give me the code" is not what StackOverflow is all about. – Burhan Khalid Jun 22 '14 at 05:35
  • Sorry...Now i edited my question. – user3763227 Jun 22 '14 at 05:41
  • To get the MySQL error occured do something like this: `$sql = "INSERT INTO ..."; if ( ! mysql_query($sql) ) { die('Could not execute MySQL query: '.mysql_error()); }` Also, use mysqli instead. http://www.php.net//manual/en/book.mysqli.php – ggirtsou Jun 22 '14 at 05:42
  • Welcome to Stack Overflow! [Please, don't use `mysql_*` functions](http://stackoverflow.com/q/12859942/1190388) in new code. They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about prepared statements instead, and use [tag:PDO] or [tag:MySQLi]. – hjpotter92 Jun 22 '14 at 05:43
  • thanks i got the output what i want.. – user3763227 Jun 22 '14 at 05:48

1 Answers1

0
$q="insert into external values(1111,'xxx','yyy')");
if(!mysql_query($q){
    die('mysql_error()');
}

This displays any error you have with that query

Dany Minassian
  • 189
  • 4
  • 13