Problem with double DB entry

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Fazzoletti9
Forum Newbie
Posts: 1
Joined: Wed Aug 31, 2011 6:10 am

Problem with double DB entry

Post by Fazzoletti9 »

Hy there,

I am heaving a little problem with a function i just wrote:

Code: Select all

	function make_auftragsnummer($name,$email,$strasse,$date){
		if($_COOKIE["auftragsnummer"]!=''){			
			return $_COOKIE["auftragsnummer"];		
		} else {
			$ergebnis=$GLOBALS['TYPO3_DB']->sql(TYPO3_db,'SELECT nummer  FROM auftragsnummer');
			$tempbool0 = true;
			
			while($tempbool0){
				$tempbool1 = false;
				$code= md5($name.$email.$strasse.$date);
				$randnum = rand(4,32);
				$auftragsnummer= "a".date(my).substr($code,-$randnum,4);
				foreach($ergebnis as $value){
					if($value==$auftragsnummer){
						$tempbool1 = true;
					}
				}
				if($tempbool1){
					$tempbool0 = true;
				}else{
					$tempbool0 = false;
				}
			}
			setcookie("auftragsnummer", $auftragsnummer, time()+3600);
			$newseintrag= "INSERT INTO auftragsnummer
    		(nummer)
			VALUES
    		('".$auftragsnummer."')";

			mysql_query($newseintrag)  OR die("Ein Fehler ist aufgetreten: ".mysql_error());
			return $auftragsnummer;
		}
	}
Each time I use this function (and the cookie is not Set) it generates two different numbers and puts them into the DB (As two entries). Does anybody know why and could send me on the right track?
Your help is much appreciated.

Ben
Post Reply