未定义的PHP变量,如何解决这个问题? [英] Undefined PHP variable, How to fix this?

查看:72
本文介绍了未定义的PHP变量,如何解决这个问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP文件就像这样:



I have a PHP file It is like this:

<?php
$myFile = "chat.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = $_POST['uname']. ": ";
fwrite($fh, $stringData);
$stringData = $_POST['msg']. "<br>";
fwrite($fh, $stringData);
fclose($fh);
?>
<!DOCTYPE html>
<html>
<head>
<div id="php">
</div>
<link rel="stylesheet" type="text/css" href="style.css"> 
<title>Red Army | Chat Room</title>
</head>
<body bgcolor="darkred">
<div id="header">
<h1 align="center">
The Red Army
</h1><br>
<h2 align="center"><a href="mems.php">Members</a>    <a href="app.php">Applications</a>    <a href="news.php">News</a>    <a href="about.php">About</a>    <a href="other.php">Other</a>
</div>
<div id="main">
<p align="center">
<div id="chatbox" class="boxed">
<?php
$myFile = "chat.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
echo $theData;
?>
</div>
<form action="?" method="post">
Username: <input type="text" name="uname"><br>
Message: <input type="text" name="msg">
<input type="submit">
</form>
<br>
<br>
<!--Ending-->
<br>
<br>
<br>
<br>
<font size="1">Coded and Founded by Jayden S</font>
<!--Ending-->
</p>
</div>
</body>



我收到未定义的变量错误,我无法设置一个post变量,或者它只是出来了等它。那么如何隐藏错误或解决错误呢? chat.txt的内容只是文件确实存在。如果你可以帮助我那会很棒。



感谢阅读!


I get the undefined variable error and I cant set a post variable or it just comes out whatever I set it to. So how do I get the error be hidden or solve the error? The contents of chat.txt are nothing but the file does exist. If you can help me that would be great.

Thanks for reading!

推荐答案

myFile = chat.txt;
myFile = "chat.txt";


fh = fopen(
fh = fopen(


myFile,' a' die( 无法打开文件);
myFile, 'a') or die("can't open file");


这篇关于未定义的PHP变量,如何解决这个问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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