At 10:02 AM -0800 12/18/01, Steve Osborne wrote:
>I would like to use an input form to add users to my database, however, if
>the name is already in use, I do not want to add a duplicate record. I also
>need this to be case insensitive (ie Santa Claus = santa Claus).
Make the (LastName, FirstName) a primary key and use INSERT IGNORE. Then test
mysql_affected_rows() to see whether it's 1 or 0. If it's 1,
the record was inserted. If it's 0, you tried to insert a dup.
>
>I've tried the following code, but it doesn't seem to be working....
>
>$chknamerow = mysql_fetch_array(runsql("SELECT FirstName,LastName FROM Names
>WHERE FirstName LIKE '$addfirstname' AND LastName LIKE '$addlastname' "));
>
> $chkname = "$chknamerow[FirstName] " . "$chknamerow[LastName]";
>
> if( ($chknamerow[FirstName]) AND ($chknamerow[LastName]) )
> {
> $Evalname = "$addfirstname2 " . "$addlastname2";
> $evalchange = " is ALREADY entered as ";
> $NewName = " $chkname";
> printf("<p class=\"subtitle\">The name %s was not added to the
>database.</p>\n", $Evalname);
> }
>
>The function runsql() is as follows:
>
>function runsql($query)
>{
> global $debugit;
> global $dbname;
> global $mysql_link;
> $runresult = mysql_db_query($dbname, $query, $mysql_link);
> if (($debugit <> "") AND ($runresult == ""))
> {
> mysql_error($mysql_link);
> echo mysql_errno().": ".mysql_error($mysql_link)." on database
>$dbname<BR>";
> echo " While running SQL: $query<BR>";
> }
> return ($runresult);
>}
>
>Any advice?
>
>Steve Osborne
>[EMAIL PROTECTED]
>
><?php
>/* Happy Holidays */
>mysql_select_db('North_Pole');
>mysql_query('SELECT reindeer FROM stable WHERE nose_color="red"');
>?>
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php