FOR loops and CASES. Help with my file creator.
Posted: Fri Nov 10, 2006 11:10 am
Im making a file, that will have a username and password sent to it and will make some files and stuff. This is what I have so far:
I want to create a whole load of files, by having a for loop changing the variable m by 1 each time. This will then go through a case statement of 1 to 20, each with a different file name, then use my prewritten code to make each of those files contain the number one. How do I do the for loop? ATM, its just not changing, it repeats that many times, but the variable $counter isn't changing.
Jcart | I've edited your code for better indentation and whitespace, at least indent properly next time please
Code: Select all
$username = md5($_GET["username"]);
$password = md5($_GET["password"]);
$filename = "$username.php";
if (!$handle = fopen($filename, 'a'))
{
die ("Error while connecting, please try again.");
}
else if (fwrite($handle, $password) === FALSE)
{
die("Error while writing.");
}
echo "Account Created to $filename";
fclose($handle);
for ($counter = 1; $counter <= 20; $counter++)
{
switch($counter)
{
case 1: $stat = "Attack";
case 2: $stat = "Cooking";
}
if (!$handle = fopen("$username$stat", 'a')) {
die ("Error while connecting, please try again.");
}
else if (fwrite($handle, 1) === FALSE)
{
die("Error while writing.");
}
}
echo "\r\n $stat level set at 1.";
fclose($handle);Jcart | I've edited your code for better indentation and whitespace, at least indent properly next time please