RE: [PHP-WIN] notify user of duplicate entry

From: Date: Thu, 28 Jun 2001 08:44:14 +0000
Subject: RE: [PHP-WIN] notify user of duplicate entry
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-8091@lists.php.net to get a copy of this message
Hi Pete, spontaneously I can give you two different ways/suggestions: 1.) Get the value 'mysql_query' returns. If it's _not_ true, call 'mysql_errno'. If it returns (1062) this means you have a dupplicate entry. --> Inform the user. 2.) make a 'SELECT COUNT(*) as num_entries FROM asset WHERE ' + your unique key of this table if the result 'num_entries' is > 0 then you have a dupplicate entry. --> Inform the user. Hope this helps. Greetinx, Mike Michael Rudel - Web-Development, Systemadministration - Besuchen Sie uns am 20. und 21. August 2001 auf der online-marketing-düsseldorf in Halle 1 Stand E 16 _______________________________________________________________ Suchtreffer AG Bleicherstraße 20 D-78467 Konstanz Germany fon: +49-(0)7531-89207-17 fax: +49-(0)7531-89207-13 e-mail: mailto:mru@suchtreffer.de internet: http://www.suchtreffer.de _______________________________________________________________ > -----Original Message----- > From: Pete Kuczynski [mailto:pkuczyns@us.dhl.com] > Sent: Wednesday, June 27, 2001 7:30 PM > To: PHP Lists > Subject: [PHP-WIN] notify user of duplicate entry > > > I want to prevent duplicate entries in by database in the hostname > field. > > So far, I have modified my hostname column as such to prevent > duplicate > entries into it, it works: > > alter table <table> modify <column> varchar(15) null unique; > > Now I need to notify the user that enters a duplicate > hostname of their > error, the database prevents the entry, but the user dosn't know it. > > Here's my PHP script, any thought how best to modify it? > > THX! > > Pete > <html> > <body> > <?php > > require("fedb.inc"); > > mysql_connect(localhost,$user,$password); > > @mysql_select_db($db) or die( "Unable to select database"); > > /*Insert into database */ > > > mysql_query ("INSERT INTO asset (site_id, hostname, > device, model, > serial, ip, > dept, mhz, ram, hd_size, os_ver, status, data_port, > pp_port, hub_port, > digi_port, csmim_port, tprmim_port, xyplex_port, > comments, fe) > VALUES ('$site_id', '$hostname', '$device', > '$model', '$serial', '$ip', > '$dept', '$mhz', '$ram', > '$hd_size', > '$os_ver', '$status', > '$data_port', '$pp_port', > '$hub_port', > '$digi_port', > '$csmim_port', '$tprmim_port', > '$xyplex_port', > '$comments', '$fe') > "); > > > > > print ($site_id); > print (" "); > > > > print ($hostname); > print (" "); > > > > print ($device); > print (" "); > > > print ($model); > > print (" "); > > print ($serial); > > print (" "); > > print ($ip); > > print (" "); > > print ($dept); > > print (" "); > > print ($mhz); > > print (" "); > > print ($ram); > > print (" "); > > print ($hd_size); > > print (" "); > > print ($os_ver); > > print (" "); > > print ($status); > > print (" "); > > print ($data_port); > > print (" "); > > print ($pp_port); > > print (" "); > > print ($hub_port); > > print (" "); > > print ($digi_port); > > print (" "); > > print ($csmim_port); > > print (" "); > > print ($tprmim_port); > > print (" "); > > print ($xyplex_port); > > print (" "); > > print ($comments); > > print (" "); > > print ($fe); > > print (" "); > > print ("<p>"); > > print ("<p>"); > > print ("Thanks for submitting your device."); > > print ("<p>"); > > print ("Please do not reload this page, it will produce > a duplicate > record"); > > > > > ?> > > <a href='index.html'><b>Home</b></a> > > > </body> > </html> > > > > > -- > _______________________________________ > Pete Kuczynski > Principal Field Engineer > DHL Airways Inc. > Infrastructure Technology & Services > (773)-462-9758 > 24/7 Helpdesk 1-800-434-5767 >

« previous php.windows (#8091) next »