Click here to Skip to main content
13,198,068 members (67,930 online)
Rate this:
Please Sign up or sign in to vote.
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">
Posted 13-Jul-13 7:36am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
Jaydman2102 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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.171020.1 | Last Updated 13 Jul 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100