file handling functions
Moderator: General Moderators
-
bluekhille
- Forum Commoner
- Posts: 25
- Joined: Thu Jul 16, 2009 6:49 am
file handling functions
how am i going to save and view records from a textbox to text file (notepad)?
here's my code for saving record but it only creates text file but it doesn't save the record.
in this code im only testing the name record
<html>
<body>
<form>
<form method = "POST" action = "mp05.php" action2 = "mp05.php">
Name
<input type = "text" name = "name"><br><br>
Address
<input type = "text" name = "address"><br><br>
Course
<input type = "text" name = "course"><br><br>
Contact
<input type = "text" name = "contact"><br><br>
Email
<input type = "text" name = "email"><br><br>
<input type = "submit" value = "View" name = "action">
<input type = "submit" value = "Save" name = "action2">
<?PHP
if(isset($_POST['action2']));
$name = $_POST['name'];
$address = $_POST['address'];
$course = $_POST['course'];
$contact = $_POST['contact'];
$email = $_POST['email'];
$file = fopen ("studinfo.txt","a");
fwrite($file,$name);
fclose($file);
?>
</form>
</body>
</hmtl>
here's my code for saving record but it only creates text file but it doesn't save the record.
in this code im only testing the name record
<html>
<body>
<form>
<form method = "POST" action = "mp05.php" action2 = "mp05.php">
Name
<input type = "text" name = "name"><br><br>
Address
<input type = "text" name = "address"><br><br>
Course
<input type = "text" name = "course"><br><br>
Contact
<input type = "text" name = "contact"><br><br>
Email
<input type = "text" name = "email"><br><br>
<input type = "submit" value = "View" name = "action">
<input type = "submit" value = "Save" name = "action2">
<?PHP
if(isset($_POST['action2']));
$name = $_POST['name'];
$address = $_POST['address'];
$course = $_POST['course'];
$contact = $_POST['contact'];
$email = $_POST['email'];
$file = fopen ("studinfo.txt","a");
fwrite($file,$name);
fclose($file);
?>
</form>
</body>
</hmtl>
Re: file handling functions
Does it not write what ever you put into the name input box to the file?
-
bluekhille
- Forum Commoner
- Posts: 25
- Joined: Thu Jul 16, 2009 6:49 am
Re: file handling functions
yeah. nothing appears on my text file
Re: file handling functions
What?? Yes it does write the name to the text file, but nothing is written to the text file??!?? That doesn't make sense...
Ok...well what does display?
Also, have you got errors turned on?
Ok...well what does
Code: Select all
var_dump($name);Also, have you got errors turned on?
-
bluekhille
- Forum Commoner
- Posts: 25
- Joined: Thu Jul 16, 2009 6:49 am
Re: file handling functions
jackpf wrote:What?? Yes it does write the name to the text file, but nothing is written to the text file??!?? That doesn't make sense...
![]()
Ok...well what doesdisplay?Code: Select all
var_dump($name);
Also, have you got errors turned on?
what i mean is anything i put on the textbox doesn't appear in the textfile..
no error appears..
Re: file handling functions
Oh right...
And what does the code I posted display?
Btw, your logic isn't completely correct, try this instead:
And what does the code I posted display?
Btw, your logic isn't completely correct, try this instead:
Code: Select all
<?PHP
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
$name = $_POST['name'];
$address = $_POST['address'];
$course = $_POST['course'];
$contact = $_POST['contact'];
$email = $_POST['email'];
$file = fopen ("studinfo.txt","a");
fwrite($file,$name);
fclose($file);
}
?>-
bluekhille
- Forum Commoner
- Posts: 25
- Joined: Thu Jul 16, 2009 6:49 am
Re: file handling functions
the other code displays word NULLjackpf wrote:Oh right...
And what does the code I posted display?
Btw, your logic isn't completely correct, try this instead:
Code: Select all
<?PHP if($_SERVER['REQUEST_METHOD'] == 'POST') { $name = $_POST['name']; $address = $_POST['address']; $course = $_POST['course']; $contact = $_POST['contact']; $email = $_POST['email']; $file = fopen ("studinfo.txt","a"); fwrite($file,$name); fclose($file); } ?>
then this one .. nothing happens
Re: file handling functions
Oh I see. You've got a nested form. Remove the form tag at the top.
-
bluekhille
- Forum Commoner
- Posts: 25
- Joined: Thu Jul 16, 2009 6:49 am
Re: file handling functions
i remove and it display thisjackpf wrote:Oh I see. You've got a nested form. Remove the form tag at the top.
string(6) "dasdwa"
Re: file handling functions
Ok, so it should be writing that to the file "studinfo.txt".