RE: [PHP-DB] address info, forms, maintanance

From: Date: Thu, 05 Jun 2003 14:07:40 +0000
Subject: RE: [PHP-DB] address info, forms, maintanance
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-28351@lists.php.net to get a copy of this message
"John W. Holmes" <holmes072000@charter.net> wrote on 06/04/2003 05:24:22 PM: > > Thanks to everyone for the suggestions. Got it fixed. Just added a > couple > > lines of code - > > $sql1 = "select * from endusers where name like '$name'"; > > $result1 = mysql_query($sql1); > > $count1 = mysql_num_rows($result1); > > if ($count1 == "0" ) > > $sql = "insert into endusers......blah blah blah > > > Now it works fine, no more duplicate entries. > > But now you're doing two queries for every insert. If you simply made > your columns unique and let the database handle it, you'd only have to > do one INSERT. Then check affected_rows() or mysql_error() to see if > either no rows were affected (no rows inserted) or the error mentions > duplicate. If either is the case, the row wasn't inserted because of a > unique constraint. If there is an error but it's not "duplicate" or > whatever, then it's another error and you should show it. > > ---John W. Holmes... Thanks for the tips, I'll work on that. In the meantime, this database is pretty low useage, very specialized information for a small market segment, so for now it will be okay. It'll never have hundreds or thousands of hits per day. But I will look into making the suggested changes. Thanks, Chip

« previous php.db (#28351) next »