Re: preventing duplicate rows?

From: Date: Thu, 13 Apr 2006 09:23:38 +0000
Subject: Re: preventing duplicate rows?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-233868@lists.php.net to get a copy of this message
You have several opportunities here : 1.If you use mysql 4.1.x you can use "insert into .. on duplicate key update" (check the correct syntax) 2.You can make unique key from the two columns and check for error number 1062 (duplicate key) like this : myusql_query($qins) or $errno=mysql_errno(); if ($errno==0)P OK! } elseif($errno ==1062){ Dupliacte! } else{ die(mysql_error()); } On Thursday April 13 2006 09:54, William Stokes wrote: > Hello, > > I'm updating a table with following SQL statement > > $sql = "INSERT INTO x_ikaluokat (ryhma, ikaluokka) > VALUES ('$ryhma','$ikaluokka')"; > > What would be the best way to test that similar rows doesn't get created to > the table? I can't make both columns unique. > > Thanks > -Will

« previous php.general (#233868) next »