Jump to content

is this script is right??


naveenbj

Recommended Posts

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

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.