Click here to Skip to main content
14,773,274 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
My php form submit page keeps failing. it gives a undefined index error at every $_POST[''] variable. I put them in brackets where I should. What is wrong?


$ourFileName = $_POST['title'] .".html";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");

$myFile = "servers.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = <<<EOD
<a href="{$_POST['title']}.html">{$_POST['title']}</a><br>
fwrite($fh, $stringData);

$myFile = $_POST['title'] .".html";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = <<<EOF
<!DOCTYPE html>
Example Forum post/Topic
<div id="post">
   <a href="servers.php">Servers</a><br>
<link rel="stylesheet" type="text/css" href="style.css">  
<title>Red Army</title> 
<body bgcolor="darkred">
<div id="header">
<h1 align="center">
The Red Army
<h2 align="center"><a href="index.php">Forum</a>    <a href="">Main Site</a>
<div id="main">
<p align="center">
<div id="post">
   {$_POST['title']} Written by {$_POST['uname']}
<div id="post">
<font size="1">Coded and Founded by Jayden S</font>
fwrite($fh, $stringData);


The first undefined index error is at line2
Here is the html form:
<form action="spost.php">
Title: <input name="title" type="text"><br>
Username (ANY): <input type="text" name="uname"><br>
Posts support html. Please put <br>  at the end of each line.<br>
<textarea rows="10" cols="50" name="post"></textarea><br>
<input type="submit" value="Post">
Updated 6-Jul-18 1:33am

The default method for a form is "get", so the inputs will be in the $_GET array instead of $_POST. To change this, modify your form element:
<form action="spost.php" method="post">

You should check to see if the values are defined and valid too - it is possible to bypass your form and directly submit data to the processing page.
G4mm4R4y 14-Jul-13 2:08am
If your talking about how its post and not get, Im not to worried about it but I fixed the issue before you answered I noticed my mistake. I fixed that BEFORE this question, but forgot to save. That's why I had trouble. But good news: My forum is up and running :D
use below code on top after php code
Patrice T 6-Jul-18 9:53am
6 years too late !
and hiding error message is not a solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900