PHP未定义索引错误 [英] PHP undefined index error

查看:114
本文介绍了PHP未定义索引错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的php表单提交页面一直失败。它在每个$ _POST ['']变量中给出一个未定义的索引错误。我把它们放在我应该的括号中。有什么问题?



代码:



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?

Code:

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


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

$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>
</div>
-->
<html> 
<head> 
<link rel="stylesheet" type="text/css" href="style.css">  
<title>Red Army</title> 
</head>
<body bgcolor="darkred">
<div id="header">
<h1 align="center">
The Red Army
</h1><br>
<h2 align="center"><a href="index.php">Forum</a>    <a href="http://www.theredarmymc.co.nf/">Main Site</a>
</div>
<div id="main">
<p align="center">
<br>
<br>
<div id="post">
   {$_POST['title']} Written by {$_POST['uname']}
   
</div><br>
<br>
<div id="post">
{$_POST['post']} 
<br>
</div>
<!--Ending-->
<br>
<br>
<br>
<br>
<font size="1">Coded and Founded by Jayden S</font>
<!--Ending-->
</p>
</div>
</body> 
</html>
EOF;
fwrite($fh, $stringData);
fclose($fh);

?>



第一个未定义的索引错误在第2行

这是html表格:


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>
<br>
Posts support html. Please put <br>  at the end of each line.<br>
<br>
<textarea rows="10" cols="50" name="post"></textarea><br>
<br>
<input type="submit" value="Post">
</form>

推荐答案

_POST ['']变量。我把它们放在我应该的括号中。有什么问题?



代码:



_POST[''] variable. I put them in brackets where I should. What is wrong?

Code:

<?php


ourFileName =
ourFileName =


_POST [' title']。 。html;
_POST['title'] .".html";


这篇关于PHP未定义索引错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆