fwrite problem

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
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

fwrite problem

Post by hob_goblin »

im trying to write a code that generates form mail scripts, it is no where near finished, so dont talk about all the security risks it has, im just having a problem with the fwrite function:

Code: Select all

<html>
 <head>
  <title>Form mail - maker</title>
  <style type="text/css">
<!--
input&#123;
	font-family:verdana;
	font-size:10 px;
	color:black;
	border:1px solid black
	&#125;
td&#123;
	font-family:verdana;
	font-size:10 px;
	color:black;
&#125;
-->
 </style>
 </head>
 <body bgcolor="#9A9A9A" text="#FFFFFF">
  <table cellpadding=0 cellspacing=0 height=100% width=100%>
   <tr>
    <td height=100% width=100% valign=top>
<?


if(!isset($doit))&#123;

/* IF ITS UNSET */
	if(!isset($pid))&#123;
echo "Welcome to form mail maker, this wizard will make a form mail script customized to you<br />\n"
."<br />Please select the number of forms..<br />"
."<form action=$PHP_SELF method=GET>\n"
."<input type=text name=num><input type=hidden value=1 name=pid><br /><input type=submit value=Go></form>";
&#125;

/* IF IT IS */
	if(isset($pid))&#123;

	if($pid == "1")&#123;

echo "<form action=$PHP_SELF method=GET>"
."Email that this form will be sent to: <input type=text name=to_email><br />\n"
."Filename of output: <input type=text name=filename><br />\n";
for($i = 1; $i <= $num; $i++)&#123;
echo $i."."." <input type=text name=_$i><br />\n";
&#125;
echo "<input type=hidden name=num value=$num>\n<input type=hidden name=pid value=2>"
."<input type=submit value=Submit></form>";

&#125; // END 1

/* SECOND STEP */

	if($pid == "2")&#123;
	if($to_email != "" AND $filename != "")&#123;
for($i = 1; $i <= $num; $i++)&#123;
$c_s = "_".$i;

if($&#123;$c_s&#125; == "")&#123;
	echo "Fill out field $i<br />\n";
&#125; else &#123;
$checkinputs = "1";
&#125;

&#125;

	if(isset($checkinputs))&#123;
$fp = fopen($filename, "w+");
for($i = 1; $i <= $num; $i++)&#123;
$c_s = "_".$i;
fwrite($fp, "$&#123;$c_s&#125;"."\n");
fclose($fp);
&#125;
&#125;

&#125; else &#123;
echo "Put in your email AND check that you specified a filename";
&#125;

&#125; // END 2


&#125; // END PID
?>

 
<?
// IF $DOIT ISNT SET
&#125; else &#123;
?>



<?
&#125;
?>
at the part where it says

Code: Select all

if(isset($checkinputs)){
$fp = fopen($filename, "w+");
for($i = 1; $i <= $num; $i++){
$c_s = "_".$i;
fwrite($fp, "${$c_s}"."\n");
fclose($fp);
}
}


it gives me fwrite errors about bad filehandle resources, it writes the first entry, but nothing past it...any ideas?
rats
Forum Newbie
Posts: 21
Joined: Fri May 31, 2002 5:55 am

Post by rats »

Code: Select all

&lt;?php
if(isset($checkinputs)){ 
  $fp = fopen($filename, "w+"); 
  for($i = 1; $i &lt;= $num; $i++){ 
    $c_s = "_".$i; 
    fwrite($fp, "${$c_s}"."\n"); 
  } 
fclose($fp); //change this maybe 
}
?&gt;
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

i didnt think that would matter but it worked, thanks :D
Post Reply