naveenbj Posted January 9, 2008 Share Posted January 9, 2008 Hello Friends, I wanted to kno tht i made any mistake in this script. here is the code. <?php if(mail()=TRUE) { $file=fopen("test.txt","r"); } fclose($file); ?> --------- Regards Nj Quote Link to comment https://forums.phpfreaks.com/topic/85146-is-this-script-is-right/ Share on other sites More sharing options...
aschk Posted January 9, 2008 Share Posted January 9, 2008 if mail() = TRUE ??? You're trying to SET the mail() function to the value of true... Quote Link to comment https://forums.phpfreaks.com/topic/85146-is-this-script-is-right/#findComment-434383 Share on other sites More sharing options...
naveenbj Posted January 9, 2008 Author Share Posted January 9, 2008 Thanks for reply!! What i want to do is to save my form info automatically in a txt format on server but im not gd in file handling and smone told me to do like this . so if you can guide me more briefly on this it would be very gr8 for me:) Regards Nj Quote Link to comment https://forums.phpfreaks.com/topic/85146-is-this-script-is-right/#findComment-434387 Share on other sites More sharing options...
adam291086 Posted January 9, 2008 Share Posted January 9, 2008 That is pretty easy. To add info into a database set up your form to post the information to a php script. In that php script use $_POST['input value name'] to get the information. Look here www.w3schools.com/php for some help. Put together some scripts. If you need help then just ask. Quote Link to comment https://forums.phpfreaks.com/topic/85146-is-this-script-is-right/#findComment-434389 Share on other sites More sharing options...
naveenbj Posted January 9, 2008 Author Share Posted January 9, 2008 Thanks for reply!! In data base its ok but if i dont want it to save to database and directly save to my server is it possible?? Quote Link to comment https://forums.phpfreaks.com/topic/85146-is-this-script-is-right/#findComment-434390 Share on other sites More sharing options...
adam291086 Posted January 9, 2008 Share Posted January 9, 2008 you can save that into a txt file. I have just googled it and found this http://php.about.com/od/advancedphp/ss/file_write_php.htm Quote Link to comment https://forums.phpfreaks.com/topic/85146-is-this-script-is-right/#findComment-434392 Share on other sites More sharing options...
naveenbj Posted January 9, 2008 Author Share Posted January 9, 2008 Thanks for reply !! But how this is the problem tht how to use code bcoz im not familier with file handling. and the code which i used is not wrking Quote Link to comment https://forums.phpfreaks.com/topic/85146-is-this-script-is-right/#findComment-434393 Share on other sites More sharing options...
adam291086 Posted January 9, 2008 Share Posted January 9, 2008 Have you got a form set up? If so show me the code Quote Link to comment https://forums.phpfreaks.com/topic/85146-is-this-script-is-right/#findComment-434396 Share on other sites More sharing options...
naveenbj Posted January 9, 2008 Author Share Posted January 9, 2008 Thanks for reply!! I have a form and here is the body> <p><FONT FACE="Verdana, Arial, Helvetica, sans-serif, Trebuchet MS" SIZE="5" COLOR="#FF9999"> <B>This is a simple example of Data Displaying from a form </B> </FONT></p><form method="post" action="welcome.php"> <P><br> <BR></P><TABLE WIDTH="40%" BORDER="0" CELLSPACING="2" CELLPADDING="1" ALIGN="CENTER" BGCOLOR="#99CCCC"><TR> <TD WIDTH="121"> <P ALIGN="LEFT"><B><I><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FF0000">First Name :-</FONT></I></B></P></TD> <TD WIDTH="487"> <P><B><I> <INPUT NAME ="name" TYPE="text"><br /> </I></B></P></TD></TR><TR> <TD WIDTH="121"> <P><B><I> <FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FF0000"> Last Name :-</FONT></I></B></P></TD> <TD WIDTH="487"> <P><B><I> <FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FF0000"><INPUT NAME ="lastname" TYPE="text"></FONT></I></B></P></TD></TR><TR> <TD WIDTH="121" HEIGHT="27"> <P><B><I><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FF0000">Email : -</FONT></I></B></P></TD> <TD WIDTH="487" HEIGHT="27"> <P><B><I> <FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FF0000"> <INPUT NAME ="email" TYPE="text"> </FONT></I></B></P> </TD> </TR><TR> <TD WIDTH="121" HEIGHT="2"> <P><B><I><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FF0000">Age:-</FONT></I></B></P></TD> <TD WIDTH="487" HEIGHT="2"> <P><B><I> <FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FF0000"> <INPUT NAME ="age" TYPE="text"> </FONT></I></B></P></TD></TR> <TR> <TD WIDTH="121"> <P><B><I><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FF0000"> Gender:-</FONT></I></B></P></TD> <TD WIDTH="487"> <P><B><I> <FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FF0000"> <INPUT TYPE="radio" NAME="radiobutton" VALUE="male"> Male <INPUT TYPE="radio" NAME="radiobutton" VALUE="female" onkeypress="return handleEnter(this, event)">Female</FONT></I></B></P></TD></TR> <TR> <TD WIDTH="121"> <P><B><I><FONT COLOR="#FF0000">Address:-</FONT></I></B></P></TD> <TD WIDTH="487"> <P><B><TEXTAREA NAME="address"></TEXTAREA></B></P></TD> </TR><TR> <TD WIDTH="121"><B><I><FONT COLOR="#FF0000">Phone:-</FONT></I></B></TD> <TD WIDTH="487"><B><I><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FF0000"> <INPUT NAME ="phone" TYPE="text"></FONT></I></B></TD></TR> <TR> <TD WIDTH="121"><B><I><FONT COLOR="#FF0000">Mobile:-</FONT></I></B></TD> <TD WIDTH="487"><B><I><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FF0000"> <INPUT NAME ="mobile" TYPE="text"></FONT></I></B></TD></TR> <TR> <TD WIDTH="121"><B><I><FONT COLOR="#FF0000">Fax:-</FONT></I></B></TD> <TD WIDTH="487"><B><I><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FF0000"> <INPUT NAME ="fax" TYPE="text"></FONT></I></B></TD></TR> <TR> <TD WIDTH="121"> </TD> <TD WIDTH="487"><B><I> <FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#FF0000"> <INPUT NAME="submit" TYPE="submit"> <INPUT TYPE="reset" NAME="Submit" VALUE="reset"> </FONT></I></B></TD></TR></TABLE> <P> </P> <P> </P> </form> </body> ------------- Regards Nj Quote Link to comment https://forums.phpfreaks.com/topic/85146-is-this-script-is-right/#findComment-434400 Share on other sites More sharing options...
adam291086 Posted January 9, 2008 Share Posted January 9, 2008 Well you have all that information going to welcome.php. In there set up the file create. Read that link i sent you http://php.about.com/od/advancedphp/ss/file_write_php.htm is's a tutorial. You should be able to follow and create what you want. Quote Link to comment https://forums.phpfreaks.com/topic/85146-is-this-script-is-right/#findComment-434404 Share on other sites More sharing options...
naveenbj Posted January 9, 2008 Author Share Posted January 9, 2008 Thanks for reply!! But in which file the code should be placed. IS in welcome.php?? Quote Link to comment https://forums.phpfreaks.com/topic/85146-is-this-script-is-right/#findComment-434406 Share on other sites More sharing options...
adam291086 Posted January 9, 2008 Share Posted January 9, 2008 At the moment your form is set to send all information to welcome.php ><form method="post" action="welcome.php"> the action part indicates where the information is sent to. First step look into $_POST of w3schools.com/php. In welcome.php get all the variable outputted to the screen. Then show me the code and I'll help you with the next step. Quote Link to comment https://forums.phpfreaks.com/topic/85146-is-this-script-is-right/#findComment-434407 Share on other sites More sharing options...
naveenbj Posted January 9, 2008 Author Share Posted January 9, 2008 Thanks for refering me this link http://php.about.com/od/advancedphp/ss/file_write_php.htm Bcoz i was trying to do this thing from last two days and i tried with few tutorials but not able to do but from ur link nad ur help now im able to get what i want exactly So thanks again Dude Best regards, Nj Quote Link to comment https://forums.phpfreaks.com/topic/85146-is-this-script-is-right/#findComment-434408 Share on other sites More sharing options...
naveenbj Posted January 9, 2008 Author Share Posted January 9, 2008 hey Bro One question the txt file is being changed each time i fill the form Can you help me again Quote Link to comment https://forums.phpfreaks.com/topic/85146-is-this-script-is-right/#findComment-434410 Share on other sites More sharing options...
adam291086 Posted January 9, 2008 Share Posted January 9, 2008 Show me the script. Do you want a new text file for every person who fills in the form? Quote Link to comment https://forums.phpfreaks.com/topic/85146-is-this-script-is-right/#findComment-434412 Share on other sites More sharing options...
naveenbj Posted January 9, 2008 Author Share Posted January 9, 2008 Thanks for reply!! here is the code which i used for this <?php $File = "YourFile.txt"; $Handle = fopen($File, 'w'); ?> <?php $File = "YourFile.txt"; $Handle = fopen($File, 'w'); fwrite($Handle, $content); print "Data Written"; fclose($Handle); ?> regards Nj Quote Link to comment https://forums.phpfreaks.com/topic/85146-is-this-script-is-right/#findComment-434414 Share on other sites More sharing options...
rajivgonsalves Posted January 9, 2008 Share Posted January 9, 2008 To save all your variables to a file it should be $strFile = "data.txt"; $strContent = "\n\n-----------------------------------\n"; foreach ($_POST as $strKey as $strValue) { $strContent .= "$strKey = $strValue\n"; } file_put_contents($strFile,$strContent,FILE_APPEND); something like that... it will only work in PHP 5 Quote Link to comment https://forums.phpfreaks.com/topic/85146-is-this-script-is-right/#findComment-434415 Share on other sites More sharing options...
naveenbj Posted January 9, 2008 Author Share Posted January 9, 2008 Thanks for reply!! Is this code will save every submisson of form data in a new txt file?? Regards Nj Quote Link to comment https://forums.phpfreaks.com/topic/85146-is-this-script-is-right/#findComment-434417 Share on other sites More sharing options...
adam291086 Posted January 9, 2008 Share Posted January 9, 2008 no it won't you need to set $strFile = "data.txt"; To be something unique everytime. At the momement everytime you run the script it will create a data.txt file and add in the information to it if it already exists Quote Link to comment https://forums.phpfreaks.com/topic/85146-is-this-script-is-right/#findComment-434419 Share on other sites More sharing options...
naveenbj Posted January 9, 2008 Author Share Posted January 9, 2008 Thanks!! So is it possible to hav a new txt file for every form submission Regards, Nj Quote Link to comment https://forums.phpfreaks.com/topic/85146-is-this-script-is-right/#findComment-434421 Share on other sites More sharing options...
rajivgonsalves Posted January 9, 2008 Share Posted January 9, 2008 first I must ask why you want to save the information to a text file... I not gone through the full post... so if you mentioned it somewhere please forgive me... is it just for loggin purpose ? Quote Link to comment https://forums.phpfreaks.com/topic/85146-is-this-script-is-right/#findComment-434423 Share on other sites More sharing options...
adam291086 Posted January 9, 2008 Share Posted January 9, 2008 You need a way to make $strFile = "data.txt"; unique everytime the script runs. It doesn't have to be data.txt. It could be a variable Quote Link to comment https://forums.phpfreaks.com/topic/85146-is-this-script-is-right/#findComment-434424 Share on other sites More sharing options...
naveenbj Posted January 9, 2008 Author Share Posted January 9, 2008 first I must ask why you want to save the information to a text file... I not gone through the full post... so if you mentioned it somewhere please forgive me... is it just for loggin purpose ? Not to be sry Quote Link to comment https://forums.phpfreaks.com/topic/85146-is-this-script-is-right/#findComment-434425 Share on other sites More sharing options...
naveenbj Posted January 9, 2008 Author Share Posted January 9, 2008 You need a way to make $strFile = "data.txt"; unique everytime the script runs. It doesn't have to be data.txt. It could be a variable Still not gettng sry Quote Link to comment https://forums.phpfreaks.com/topic/85146-is-this-script-is-right/#findComment-434426 Share on other sites More sharing options...
adam291086 Posted January 9, 2008 Share Posted January 9, 2008 ok at the moment using the script by rajivgonsalves $strFile = "data.txt"; $strContent = "\n\n-----------------------------------\n"; foreach ($_POST as $strKey as $strValue) { $strContent .= "$strKey = $strValue\n"; } file_put_contents($strFile,$strContent,FILE_APPEND); If the file data.txt does exist then it takes all the form information and adds it to the file. If you change data.txt too data1.txt then that information will be changed. Therefore you need away to change data.txt everytime the script run. Quote Link to comment https://forums.phpfreaks.com/topic/85146-is-this-script-is-right/#findComment-434431 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.