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
andylyon87
Forum Contributor
Posts: 168 Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee
Post
by andylyon87 » Fri Jul 02, 2004 1:07 pm
Code: Select all
<?php
function WriteToFile($firstname){
$TheFile = "php/form_data/focus/$array[shop_name]/contact.txt";
$Open = fopen ($TheFile,"a+");
if($Open){
fwrite ($Open,"$firstname");
fclose($Open);
$Worked=True;
} else {
$Worked = False;
}
return $Worked;
}//end of write to file function
?>
Why doesn't this put the file in the correct folder, thought it was strings so used:
Code: Select all
<?php
$TheFile = "php/form_data/focus/".$array[shop_name]."/contact.txt";
?>
As this is usually how you fuse variables with the normal isn't it. the file gets written but in the focus folder. the $array[shop_name] variable has had its own directory created and it appears ok
redmonkey
Forum Regular
Posts: 836 Joined: Thu Dec 18, 2003 3:58 pm
Post
by redmonkey » Fri Jul 02, 2004 2:20 pm
$array is not accessable by the function i.e. it is outside the variable scope of the function.
Calimero
Forum Contributor
Posts: 310 Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way
Post
by Calimero » Fri Jul 02, 2004 3:16 pm
Code: Select all
<?php
$TheFile = "php/form_data/focus/".$array[shop_name]."/contact.txt";
?>
// have you tried / in front of the name of the
php/form_data/focus/".$array[shop_name]."/contact.txt";
Ex
Code: Select all
<?php
$TheFile = "/php/form_data/focus/".$array[shop_name]."/contact.txt";
?>
andylyon87
Forum Contributor
Posts: 168 Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee
Post
by andylyon87 » Sat Jul 03, 2004 3:39 am
Doesn't apear to be workin have also tried using if statements
Code: Select all
<?php
function WriteToFile($firstname){
$Open = fopen ($TheFile,"a+");
if($Open){
fwrite ($Open,"$firstname");
fclose($Open);
$Worked=True;
} else {
$Worked = False;
}
return $Worked;
}//end of write to file function
?>
Code: Select all
<?php
function handleform(){
global $array;
$make = mkdir("php/form_data/focus/$array[shop_name]", 0666);
if($make){
if($array[overview]){
$TheFile = "php/form_data/focus/".$array[shop_name]."/overview.txt";
WriteToFile("Overview Of Company:\n \t$array[company]\n");}
if($array[shop_name]){
$TheFile = "php/form_data/focus/".$array[shop_name]."/contact.txt";
WriteToFile("Representatives Name: $array[name]\nCompany Name: $array[shop_name]\nCompany Contact (Tel): $array[contact]\nCompany Contact (E-mail): $array[email]\nWebsite Address: $array[address]\n");}
mail("lyonclan@onetel.net.uk", "new_focus", "$array[shop_name]", "from:$array[name]" );
print("<TABLE width=450 cellpadding=0 cellspacing=0 border=0>
<TR>
<TD>Thank you $array[name].</TD>
</TR>
</TABLE>\n");
}else{
print("directory could not be created for you");
}
}
if($array[beensubmitted]){
handleform();
}
createform();
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Jul 03, 2004 5:44 am
andy, you're getting into a real bad habit of not quoting your indexes into the array...
why not pass $array to the function?
andylyon87
Forum Contributor
Posts: 168 Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee
Post
by andylyon87 » Sat Jul 03, 2004 8:25 am
I dont understand what your gettin at show me what you mean. And what dyou mean quote my indexes?
Lastly if you mean put $thefile into the function WriteToFile() I already tried that and that doesn't work.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Jul 03, 2004 8:58 am
How about this:
Code: Select all
<?php
function WriteToFile($TheFile,$firstname){
$Open = fopen ($TheFile,"a+");
if($Open){
fwrite ($Open,"$firstname");
fclose($Open);
$Worked=True;
} else {
$Worked = False;
}
return $Worked;
}//end of write to file function
function handleform($array){
if(!is_array($array)) return false;
$make = mkdir("php/form_data/focus/$array[shop_name]", 0666);
if($make){
if($array['overview']){
$TheFile = "php/form_data/focus/".$array['shop_name']."/overview.txt";
WriteToFile($TheFile,"Overview Of Company:\n \t$array[company]\n");}
if($array['shop_name']){
$TheFile = "php/form_data/focus/".$array['shop_name']."/contact.txt";
WriteToFile($TheFile,"Representatives Name: $array[name]\nCompany Name: $array[shop_name]\nCompany Contact (Tel): $array[contact]\nCompany Contact (E-mail): $array[email]\nWebsite Address: $array[address]\n");}
mail("lyonclan@onetel.net.uk", "new_focus", "$array[shop_name]", "from:$array[name]" );
print("<TABLE width=450 cellpadding=0 cellspacing=0 border=0>
<TR>
<TD>Thank you $array[name].</TD>
</TR>
</TABLE>\n");
}else{
print("directory could not be created for you");
}
}
if($array['beensubmitted']){
handleform($array);
}
createform();
?>
andylyon87
Forum Contributor
Posts: 168 Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee
Post
by andylyon87 » Sat Jul 03, 2004 12:37 pm
ok but doesn't the
Code: Select all
<?php
if(!is_array($array)) return false;
?>
lne just translate to
and why do you use the handleform($array)
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Jul 03, 2004 3:47 pm
because it's better to pass data into functions, than use the global system (most of the time)
and no, is_array($array) does not translate into global $array.