...

View Full Version : trouble with a php process



mkphoto44
02-13-2006, 01:00 AM
I have set up a form and when I click on submit I get the following error message:

Warning: fopen(admin/data.dat): failed to open stream: No such file or directory in /home/mlkphoto/public_html/process.php on line 33

Warning: fwrite(): supplied argument is not a valid stream resource in /home/mlkphoto/public_html/process.php on line 37

Warning: Cannot modify header information - headers already sent by (output started at /home/mlkphoto/public_html/process.php:33) in /home/mlkphoto/public_html/process.php on line 39

What does this mean and how do I fix it? I do get the form information sent to my email so I know it's going through. I just can't get a "Thank you" page to come up and I get the error messages. Thanks in advance

chump2877
02-13-2006, 01:29 AM
Show us some code that would help a bit....


Warning: fopen(admin/data.dat): failed to open stream: No such file or directory in /home/mlkphoto/public_html/process.php on line 33

for that error, probably the path to your file is incorrect...try using the full absolute path, whatever that is on your server...for example:


/home/httpd/vhosts/yourdomain.com/httpdocs/admin/data.dat

Or try using the full URL, for example:


http://www.yourdomain.com/admin/data.dat

mkphoto44
02-13-2006, 01:31 AM
Here is the code that I am working with:

<form enctype='multipart/form-data' action='process.php' method='post'>
<div align="center">
<table border="1" cellspacing="1" style="border-collapse: collapse" bordercolor="#000066" width="51%" cellpadding="5">
<tr> </tr>
<tr>
<td colspan="3" bgcolor="#B5CBEF" height="16" width="100%" bordercolor="#FFFFFF" background="tile_sub.gif"><font size="2" face="Verdana"><b><font face="Verdana" size="2" color="#000066">
<!- You can add a brief form description here-->
&nbsp; </font></b></font></td>
</tr>
<tr>
<td height="30" width="189" bgcolor="#EFF3F7" bordercolor="#FFFFFF"> <font face="Verdana" size="2">First
Name</font></td>
<td height="30" width="469" bgcolor="#EFF3F7" bordercolor="#FFFFFF"> <font face="Verdana">
<input type=text name='FirstName'>
</font></td>
</tr>
<tr>

<td height="30" width="189" bgcolor="#EFF3F7" bordercolor="#FFFFFF"> <font face="Verdana" size="2">Last
Name</font></td>
<td height="30" width="469" bgcolor="#EFF3F7" bordercolor="#FFFFFF"> <font face="Verdana">
<input type=text name='LastName'>
</font></td>
</tr>
<tr>

<td height="30" width="189" bgcolor="#EFF3F7" bordercolor="#FFFFFF"> <font face="Verdana" size="2">Wedding
Date</font></td>
<td height="30" width="469" bgcolor="#EFF3F7" bordercolor="#FFFFFF"> <font face="Verdana">
<input type=text name='WeddingDate'>
</font></td>
</tr>
<tr>

<td height="30" width="189" bgcolor="#EFF3F7" bordercolor="#FFFFFF"> <font face="Verdana" size="2">City</font></td>
<td height="30" width="469" bgcolor="#EFF3F7" bordercolor="#FFFFFF"> <font face="Verdana">
<input type=text name='City'>
</font></td>
</tr>
<tr>

<td height="30" width="189" bgcolor="#EFF3F7" bordercolor="#FFFFFF"> <font face="Verdana" size="2">State</font></td>
<td height="30" width="469" bgcolor="#EFF3F7" bordercolor="#FFFFFF"> <font face="Verdana">
<input type=text name='State'>
</font></td>
</tr>
<tr>

<td height="30" width="189" bgcolor="#EFF3F7" bordercolor="#FFFFFF"> <font face="Verdana" size="2">Zip
Code</font></td>
<td height="30" width="469" bgcolor="#EFF3F7" bordercolor="#FFFFFF"> <font face="Verdana">
<input type=text name='ZipCode'>
</font></td>
</tr>
<tr>

<td height="30" width="189" bgcolor="#EFF3F7" bordercolor="#FFFFFF"> <font face="Verdana" size="2">Daytime
Phone</font></td>
<td height="30" width="469" bgcolor="#EFF3F7" bordercolor="#FFFFFF"> <font face="Verdana">
<input type=text name='DaytimePhone'>
</font></td>
</tr>
<tr>

<td height="30" width="189" bgcolor="#EFF3F7" bordercolor="#FFFFFF"> <font face="Verdana" size="2">Evening
Phone</font></td>
<td height="30" width="469" bgcolor="#EFF3F7" bordercolor="#FFFFFF"> <font face="Verdana">
<input type=text name='EveningPhone'>
</font></td>
</tr>
<tr>

<td height="30" width="189" bgcolor="#EFF3F7" bordercolor="#FFFFFF"> <font face="Verdana" size="2">EMail
Address</font></td>
<td height="30" width="469" bgcolor="#EFF3F7" bordercolor="#FFFFFF"> <font face="Verdana">
<input type=text name='EMailAddress'>
</font></td>
</tr>
<tr>
<td colspan="3" bgcolor="#B5CBEF" height="25" width="737" background="tile_sub.gif"><p align="center"><font face="Verdana" size="2">
<input name="submit" type=submit value='Submit Form'>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<input name="reset" type=reset value='Reset Form'>
</font></td>
</tr>
</table>
</div>
</form>

Thank you for any help you can give.

chump2877
02-13-2006, 01:32 AM
please use PHP tags to enclose your code


By the way, lol, thats the HTML file, show us the offending code from your PHP file (that processes the form)....the error messages are telling you what lines the errors are ocurring on...any script editor will let you view line numbers, so then you can isolate the code for us

mkphoto44
02-13-2006, 01:35 AM
Sorry - here is the right code:

<?php
include("global.inc.php");
$errors=0;
$error="The following errors occured while processing your form input.<ul>";
pt_register('POST','FirstName');
pt_register('POST','LastName');
pt_register('POST','WeddingDate');
pt_register('POST','City');
pt_register('POST','State');
pt_register('POST','ZipCode');
pt_register('POST','DaytimePhone');
pt_register('POST','EveningPhone');
pt_register('POST','EMailAddress');
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$EMailAddress)){
$error.="<li>Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;
else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="First Name: ".$FirstName."
Last Name: ".$LastName."
Wedding Date: ".$WeddingDate."
City: ".$City."
State: ".$State."
Zip Code: ".$ZipCode."
Daytime Phone: ".$DaytimePhone."
Evening Phone: ".$EveningPhone."
EMail Address: ".$EMailAddress."
";
$message = stripslashes($message);
mail("mkphoto44@comcast.net","Form Submitted at your website",$message,"From: phpFormGenerator");
$make=fopen("admin/data.dat","a");
$to_put="";
$to_put .= $FirstName."|".$LastName."|".$WeddingDate."|".$City."|".$State."|".$ZipCode."|".$DaytimePhone."|".$EveningPhone."|".$EMailAddress."
";
fwrite($make,$to_put);

header("Refresh: 0;url=http://photosbymlkeen.com/ThankYou.html");
?><?php
}
?>

chump2877
02-13-2006, 01:42 AM
<?php

ob_start();

include("global.inc.php");
$errors=0;
$error="The following errors occured while processing your form input.<ul>";
pt_register('POST','FirstName');
pt_register('POST','LastName');
pt_register('POST','WeddingDate');
pt_register('POST','City');
pt_register('POST','State');
pt_register('POST','ZipCode');
pt_register('POST','DaytimePhone');
pt_register('POST','EveningPhone');
pt_register('POST','EMailAddress');
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$EMailAddress)){
$error.="<li>Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;
else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="First Name: ".$FirstName."
Last Name: ".$LastName."
Wedding Date: ".$WeddingDate."
City: ".$City."
State: ".$State."
Zip Code: ".$ZipCode."
Daytime Phone: ".$DaytimePhone."
Evening Phone: ".$EveningPhone."
EMail Address: ".$EMailAddress."
";
$message = stripslashes($message);
mail("mkphoto44@comcast.net","Form Submitted at your website",$message,"From: phpFormGenerator");
$make=fopen("admin/data.dat","a");
$to_put="";
$to_put .= $FirstName."|".$LastName."|".$WeddingDate."|".$City."|".$State."|".$ZipCode."|".$DaytimePhone."|".$E veningPhone."|".$EMailAddress."
";
fwrite($make,$to_put);

fclose($make);

ob_end_flush();

header("Refresh: 0;url=http://photosbymlkeen.com/ThankYou.html");
?><?php
}
?>

that will probably fix your header problem...i already told you what to do with the "opening the file" issue...

mkphoto44
02-13-2006, 02:10 AM
Thank you for your help. There is still a little gliche but for the most part it's doing what it should. It just seems that an error message flash very quickly on the screen but then goes to the Thank you page.

chump2877
02-13-2006, 02:24 AM
that's probably some of your own built in error checking....an echo or print statement somewhere that is showing up when you flush the output buffer with ob_end_flush()....so there is probably something else still wrong with your script....can you see/read the error?

I always put my error messages inside die() so that the script stops execution when my built in error checking picks up on something,,,maybe replace your echo statements with die() somewhere....then the script will stop so you can fix the small problem that is left....

chump2877
02-13-2006, 02:30 AM
change


if($errors==1) echo $error;

to



if($errors==1) die($error);

mkphoto44
02-13-2006, 03:09 AM
When I put the code:
if($errors==1) die($error);

I get the error:
Parse error: syntax error, unexpected T_VARIABLE in /home/mlkphoto/public_html/process.php on line 21

You asked if I could read the error before. It flashes on the screen and the goes away to fast to read. Is there a way to see what's going on? Thanks again for your help

mkphoto44
02-13-2006, 03:18 AM
I left out the () around ($error) so that's why I was getting the last error message. I am still getting what looks like 2 error messages flash very quickly across the screen before it goes to the Thank you page. Any additional help would be appreciated.

mkphoto44
02-13-2006, 01:35 PM
I was able to see the error message and it is as follows:

Warning: fopen(admin/data.dat): failed to open stream: No such file or directory in /home/mlkphoto/public_html/process.php on line 36

Warning: fwrite(): supplied argument is not a valid stream resource in /home/mlkphoto/public_html/process.php on line 40

Line 36 is:
$make=fopen("admin/data.dat","a");

I'm not sure what the admin/data.dat is representing. I looked in all the files on the server and couldn't find it.

Line 40 is:
fwrite($make,$to_put);

Any help would be appreciated. Thanks

Zegg90
02-13-2006, 04:16 PM
I'm not sure what the admin/data.dat is representing. I looked in all the files on the server and couldn't find it.
And there's your problem. The script is trying to open data.dat, but the file doesn't exist. Did you writethe script yourself? If you aren't using data.dat for anything, then I suppose you can just delete those lines.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum