I am trying to write & read to a file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I created a form that asks for the users 1st and last
name. I than try and attempt to save this data to a
file. Next, I'd like to read the data from this file
and write its contents to the browser.

I only get so far before I get a wierd response after
hitting the submit button: 

Resource id #3

See code below:

<?php
$firstnm =  $_POST['firstnm']; //creates 1st var
$lastnm =  $_POST['lastnm']; //create 2nd var

$filename = "names.txt"; //creates file to write the
//above variable values to
print "writing to $names.txt"; 

$fp = fopen( "names.txt", "w" ) or die("couldn't open
$names"); //opens the file I created
fwrite( $fp, "$firstnm\n" , "$lastnm"); //I don't know
//if this is right, but I attempt to write the
//variables to the file //here.
fclose( $fp ); //close the file
print "$fp_names"; //attempt to print the files
//contents to the browser here- but it does not work
$contents = file_get_contents( "names.txt" );
//attempts to read from file
print "$contents"; //attempts to display contents to
//browser


?>


<!DOCTYPE html PUBLIC
	"-//W3C//DTD XHTML 1.0 Strict/EN"
	"http://www/w3/org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
<html>
<head>
<title>form</title>

</head>
<body>
<h1>
<?php print "$fp" ?>
</h1>
<form method="post" action="<?php print
$_SERVER['PHP_SELF']?>">
<p>
Type your 1st name here: <input type="text"
name="firstnm" /><br />
Type your last name here: <input type="text"
name="lastnm" /><br />
<p><input type="submit" value="submit" /></p>

	
</p>
</form>
</body>
</html>


=====

----------------
"forget your lust for the rich man's gold. All that you need, is in your soul. You can do this if you try. All that I want for you my son, is to be satisfied"

  ~ Lynard Skynard

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux