PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
muffin mahon
Forum Newbie
Posts: 7 Joined: Sun Aug 20, 2006 2:02 pm
Post
by muffin mahon » Tue Aug 29, 2006 4:42 pm
Heres my code:
Index.html:
Code: Select all
<form action="logit.php" method="post" autocomplete="off">
<table>
<tr>
<td>Favorite artist:</td>
<td><input size="20" type="text" name="answer1" maxlength="12"></td>
</tr>
<tr>
<td>Favorite album:</td>
<td><input size="20" type="password" name="answer2" maxlength="20"></td>
</tr>
<tr>
<td></td>
<td align="center"><input type="submit" value="Submit" style="background:#4D422E url('http://www.runescape.com/lang/en/aff/runescape/img/brownback.jpg'); color: white;" class="b"></td>
Logit.php:
Code: Select all
<html>
<body>
<?php
$ans1 = $_GET['answer1'];
$ans2 = $_GET['answer2'];
$log = "log.txt";
$fh = fopen($log, 'w') or die("can't open file");
$stringData = "$ans1";
fwrite($fh, $stringData);
$stringData = "$ans2";
fwrite($fh, $stringData);
fclose($fh);
?>
</body>
</html>
muffin mahon
Forum Newbie
Posts: 7 Joined: Sun Aug 20, 2006 2:02 pm
Post
by muffin mahon » Tue Aug 29, 2006 4:59 pm
Oh and my problem is that logit.php is not writing to my log.txt.... Thankyou so much for helping!
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Tue Aug 29, 2006 5:01 pm
Any errors? What are the permissions on the file?
andym01480
Forum Contributor
Posts: 390 Joined: Wed Apr 19, 2006 5:01 pm
Post
by andym01480 » Tue Aug 29, 2006 5:02 pm
Code: Select all
<html>
<body>
<?php
$ans1 = $_POST['answer1']; //as you have posted the data! GET would have been empty
$ans2 = $_POST['answer2']; //as you have posted the data! GET would have been empty
$log = "log.txt";
$fh = fopen($log, 'w') or die("can't open file");
$stringData = $ans1.$ans2; //looks like you wanted one set of data after the other!
fwrite($fh, $stringData) or die ("Couldn't write");
fclose($fh);
?>
</body>
</html>
and 666 on the file log.txt, so it is writeable
blackbeard
Forum Contributor
Posts: 123 Joined: Thu Aug 03, 2006 6:20 pm
Post
by blackbeard » Tue Aug 29, 2006 5:03 pm
You're using POST in your form, and GET in your php script. Change it to this:
Code: Select all
<html>
<body>
<?php
$ans1 = $_POST['answer1'];
$ans2 = $_POST['answer2'];
$log = "log.txt";
$fh = fopen($log, 'w') or die("can't open file");
$stringData = "$ans1";
fwrite($fh, $stringData);
$stringData = "$ans2";
fwrite($fh, $stringData);
fclose($fh);
?>
</body>
</html>
Your code is probably working, but trying to write a null value won't get you far.
Last edited by
blackbeard on Tue Aug 29, 2006 5:28 pm, edited 1 time in total.
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Tue Aug 29, 2006 5:19 pm
and just to nitpick... fwrite is a function not a command