mysql - PHP loop creating duplicate database rows -
i'm playing creating database contains plaintext , hash values combination of passwords, when added database end many duplicates before moves on next combination... ideas why , how stop it?
<?php $con=mysqli_connect("localhost","root","","test"); // check connection if (mysqli_connect_errno()) { echo "failed connect mysql: " . mysqli_connect_error(); } $numberof=0; $alphabet = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"); for($i=0; $i<count($alphabet); $i++){ for($j=0; $j<count($alphabet); $j++){ for($k=0; $k<count($alphabet); $k++){ for($l=0; $l<count($alphabet); $l++){ $final = $alphabet[$i].$alphabet[$j].$alphabet[$k]; $hash = md5($final); mysqli_query($con,"insert hashes (plain, hash) values ('$final', '$hash')"); } } } } echo $numberof; ?>
you have 4 nested for
loops, counters $i
$j
$k
, $l
. however, final string use in query uses $i
$j
, $k
you'll have 26 duplicates. assume meant append value of $l
end of string?
Comments
Post a Comment