priblem with forum reply script!

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

Post Reply
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

priblem with forum reply script!

Post by dull1554 »

heres my code
add_reply.php

Code: Select all

<html>
<head>
</head>
<body>
<form method="post" action="add_reply.php">

Subject:<br><input type="text" name="subject">
<br>
Reply body:<br><textarea cols="75" rows="25" name="body"></textarea>
<br>
<input type="submit" value="reply">
</form>

</body>
</html>
<?php
$filename = $_GET['reply'];
$reply_body = $_GET['body'];
$username = (@$_COOKIE['complexscriptingusername']);
$insertreply = "<table width='100%' border='0' cellspacing='1' cellpadding='2' bgcolor='#dcdcdc' align='center'>
<tr><td width='80%' border='1' bgcolor='whitesmoke'>".$reply_body."</td>
<td width='20%' border='1' bgcolor='whitesmoke'>
Reply by: ".$username."</td></tr></table>";
$fp = fopen($filename, "a");
fwrite($fp,$insertreply);
fclose($fp);
?>
i get this error when i got to the script

Code: Select all

Notice: Undefined index: body in d:\web\dull1554\forum\add_reply.php on line 20
and if i try to submit the forum i get these,

Code: Select all

Notice: Undefined index: reply in d:\web\dull1554\forum\add_reply.php on line 19

Notice: Undefined index: body in d:\web\dull1554\forum\add_reply.php on line 20

Warning: fwrite(): supplied argument is not a valid stream resource in d:\web\dull1554\forum\add_reply.php on line 27

Warning: fclose(): supplied argument is not a valid stream resource in d:\web\dull1554\forum\add_reply.php on line 28
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Check these two:

$filename = $_GET['reply'];
$reply_body = $_GET['body'];

Undefined index means that the variables are not stated.

And didn't I run into you with a heredoc suit already? :lol:

-Nay
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Form method is POST (good) but you're looking for vars in $_GET.

Try this to check POST vars:

Code: Select all

<?php
echo '<pre>';
print_r($_POST);
echo '</pre>';
?>
Post Reply