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
m0u53m4t
Forum Contributor
Posts: 101 Joined: Wed Apr 19, 2006 7:47 am
Location: Wales
Post
by m0u53m4t » Fri Nov 10, 2006 6:42 pm
My code all works so far, but its suppost to make files with each of the case names, but doesn't, just 6 all called attack atm. Any ideas?
Code: Select all
<?php
$username = $_GET["username"];
$password = $_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 "$username's account has been created";
fclose($handle);
$loop=1;
for ( $counter = 1; $counter <= 6; $counter ++ ) {
$loop == $loop+1;
switch($loop){
case 1: $stat = "Attack";
case 2: $stat = "Cooking";
case 3: $stat = "Crafting";
case 4: $stat = "Defence";
case 5: $stat = "Firemaking";
case 6: $stat = "Fishing";
}
if (!$handle = fopen("$username$stat.php", 'a')) {
die ("Error while connecting, please try again.");
} else {
if (fwrite($handle, '<title>1</title>') === FALSE){
die("Error while writing.");
}
}
echo "<br>$stat level set at 1.";
fclose($handle);
}
?>
shiznatix
DevNet Master
Posts: 2745 Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:
Post
by shiznatix » Fri Nov 10, 2006 6:46 pm
$loop == $loop+1;
your doing a comparison and not reassigning the value. fix that and you should be good.
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Fri Nov 10, 2006 6:53 pm
you also need to break out of your switch when you match a value.
m0u53m4t
Forum Contributor
Posts: 101 Joined: Wed Apr 19, 2006 7:47 am
Location: Wales
Post
by m0u53m4t » Sat Nov 11, 2006 5:53 am
Thanks guys! This is it fully corrected. Im sure I'll have some questions about this later though...
Code: Select all
<?php
$username = $_GET["username"];
$password = $_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 "$username's account has been created";
fclose($handle);
$loop=0;
for ( $counter = 1; $counter <= 5; $counter ++ ) {
$loop = $loop+1;
switch($loop){
case 1: $stat = "Attack"; break;
case 2: $stat = "Crafting"; break;
case 3: $stat = "Defence"; break;
case 4: $stat = "Firemaking"; break;
case 5: $stat = "Fishing"; break;
}
if (!$handle = fopen("$username$stat.php", 'a')) {
die ("Error while connecting, please try again.");
} else {
if (fwrite($handle, '<title>1</title>') === FALSE){
die("Error while writing.");
}
}
echo "<br>$stat level set at 1.";
fclose($handle);
}
?>