Hi, Can anyone help I'm going mad with this... I'm using postgresql with php and writing a small login and sign-up system. Whena user wishes to sign-up Iwant to check there are not any other users with the same username, so I'm doing a select against the db with the requested username before allowing the insert to add the user to the db. For some reason the code I'm using seems to be running through the fucntion twice sometimes!!! and other times runs as it should!!! Thanks for any help or ideas. Zac The code in the top of the html page calling the function: <?php // - - - - form processing if($_REQUEST[Username]){ // - - - - - include login code page include_once "/wrt/fl/htdocs/incs/cde/usr_lg.html"; // - - - - check for redirect if(isset($_SESSION[Rdr])){ $Rdr = $_SESSION[Rdr]; } else { $Rdr = $c01_user_login_redirect; } $ChckVal = array("Username","Password","Country"); Mmbr_SgnUp($ChckVal, $Rdr); #Usr_Lgn($Rdr); } ?> The function it's self : function Mmbr_SgnUp($ChkVal, $Rdr){ /* Will check that each element in ChkVal array has a $_POST value not null Will check no duplicates of unique column Will redirect to success or fail with error message HTML Form Elements should be called Username, Password, Preffered, Reminder, Country, ChkVal array of element names to be checked Rdr page to redirect to if successful Standard begining to error message */ $GLOBALS[dbgPos] = 'Mmbr_SgnUp function'; if($GLOBALS[c01_debug]) echo '<h2> Debugging from New Member Sign Up Function </h2><blockquote>'; // - - - - - - - - define function vars // - - - - - - - - array for errors that occured $Err = array(); // - - - - - - - - array for noting missing elements in sign up $EmtErr = array(); // - - - - - - - - check that each form element has been completed ForEach($ChkVal as $val){ // - - - - - - - - if element is not set add element to error array if(!isset($_REQUEST[$val])){ array_push($EmtErr,$val); $Err[0] = $GLOBALS[c01_Err_21]; } } if($GLOBALS[c01_debug]){ // - - - - - - write ChkVal array to screen wrt_arr_scrn($ChkVal); echo 'Rdr = '.$Rdr.'<br><br>'; } // - - - - - - - - Check for duplicate values in db // - - - - - - - - create db connecion $Con = dbc(); $Qry = dbq('SELECT "UsrId" FROM "Usr" WHERE "UsrId" = '."'".$_REQUEST[Username]."'".';'); for($r = 0 ; $r < 10000; $r++){ echo $r; } if($GLOBALS[c01_debug]) echo 'SELECT "UsrId" FROM "Usr" WHERE "UsrId" = '."'".$_REQUEST[Username]."'".';<br><br>'; if(db_num_rows($Qry) > $GLOBALS[c01_0]){ $Row = db_fetch_row($Qry); echo $Row[0]; $Err[1] = $GLOBALS[c01_Err_20]; if($GLOBALS[c01_debug]) echo ' Check for more than one entry NumRows returned - '.db_num_rows($Qry).'<br><br>'; // - - - - - - - - log new member sign-up failure wrt_log($GLOBALS[c01_log_level_usr],$GLOBALS[c01_t],'New_Member','*** FAILED Sign-up at '.$GLOBALS[c05_DteTme].', Username = '.$_POST[Username].', Err[0] = '.$Err[0].', Err[1] = '.$Err[1]." \n"); if($GLOBALS[c01_debug]) echo '</blockquote><h2> End Debugging from New Member Sign Up Function </h2>'; // - - - - - - - - return errors $Err["missing"] = $EmtErr; return $Err; } else { // - - - - - - - - Check if signup was successful if($GLOBALS[c01_debug]) echo'No Errors In passed data Proceding to write to DB<br><br>'; // - - - - - - - - insert record into db $cols = '"Sts","StsDtm","IniDtm","LgiDtm","Usr_MlcKey","UsrId","Pwd"'; $vals = '1,'."'".$GLOBALS[c05_Dte]."'".','."'".$GLOBALS[c05_DteTme]."'".','."'".$GLO BALS[c05_DteTme]."'".','."'".$_POST[Country]."'".','."'".$_POST[Username]."' ".','."'".$_POST[Password]."'"; if($_POST[Preffered] != ''){ echo 'pp'.$_POST[Preffered].'pp<br>'; $cols.= ',"PrfNme"'; $vals.= ','."'".$_POST[Preffered]."'"; } $Qry = dbq('INSERT INTO "Usr" ('.$cols.') Values ('.$vals.');'); // - - - - - - - - get usrid $Uid = db_insert_id($Qry); if($GLOBALS[c01_debug]) echo 'Get DB OID - '.$Uid.'<br><br>'; if($_POST[Reminder]){ // - - - - - - - - add other details to Udt ~ password reminder $Qry = dbq('INSERT INTO "Udt" ("Udt_UsrKey", "PwdRmd") VALUES ('.$Uid.', '."'".$_POST[Reminder]."'".');'); } // - - - - - - - - log new member sign-up wrt_log($GLOBALS[c01_log_level_usr],$GLOBALS[c01_t],'New_Member','SUCCESSFUL Sign-up at '.$GLOBALS[c05_DteTme].', UserId = '.$Uid." \n "); // - - - - - - - - add freebies for becoming a new member $frb = add_frb('BNM001', $Uid); if($GLOBALS[c01_debug]) echo ' Add Freebies for Sign Up<br><br>'; // - - - - - - - - login ~ which will result in redirect if($GLOBALS[c01_debug]) echo 'Now Goto Login Function to Log User in'; if($GLOBALS[c01_debug]) echo '</blockquote><h2> End Debugging from New Member Sign Up Function </h2>'; #Usr_Lgn($Rdr); } } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php