php get方法问题
2018-08-20 17:50:34
[PHP讨论组]

<?php

echo '<h1>留言区</h1>';

echo '<form action="message.php" method="GET">';


echo '用户名:<input type="text" name="username" /><br />';

echo '留言:<textarea name="content"></textarea><br />';

echo '<input type="submit" value="确认" />';

echo '</form>';


$username=$_GET['username'];

$content=$_GET['content'];

$file=fopen('message.txt','a');

$w_content="$username : $content";

fwrite($file,$w_content);

//fclose($file);

echo file_get_contents('message.txt');



?>

为啥接收不到form里面的$username 和 $content变量?

全部回复(6)
嘿哈

我把你的代码 拿到本地测试了下  我是能收得参数的,一步一步的测试 看看是哪里出了问题

  • 回复 怎么测试?这个代码在别的机器上运行是可以get到值的。。就我的这个机器上不行
    作者 2018-08-21 18:23:02
  • 回复 不可能吧 你试试放在 localhost运行
    vec 作者 2018-08-22 12:58:03
vec

&lt;?phpecho &#39;&lt;h1&gt;留言区&lt;/h1&gt;&#39;;echo &#39;&lt;form&nbsp; method=&quot;GET&quot;&gt;&#39;;echo &#39;用户名:&lt;input type=&quot;text&quot; name=&quot;username&quot; /&gt;&lt;br /&gt;&#39;;echo &#39;留言:&lt;textarea name=&quot;content&quot;&gt;&lt;/textarea&gt;&lt;br /&gt;&#39;;echo &#39;&lt;input type=&quot;submit&quot; value=&quot;确认&quot; /&gt;&#39;;echo &#39;&lt;/form&gt;&#39;;$username=isset($_GET[&#39;username&#39;]);$content=isset($_GET[&#39;content&#39;]);$file=fopen(&#39;message.txt&#39;,&#39;a&#39;);$w_content=&quot;$username : $content&quot;;fwrite($file,$w_content);//fclose($file);echo file_get_contents(&#39;message.txt&#39;);?&gt;建议在传值的时候加上isset方法&nbsp;

vec

传值没有问提 本地测试了一下 不过echo的数据应该不对

vec

是undefined index吗?


vec

错误提示是什么咧?

  • 回复 这个代码在别的机器上运行是可以get到值的。。就我的这个机器上不行
    作者 2018-08-21 18:23:31
  • 回复 大概问题知道了,可能是文件没有打开。。
    作者 2018-08-21 18:24:52
  • 回复 知道问题了,var_dump($file)返回了false
    作者 2018-08-21 18:28:56
好名字

你的form里的action确定指向正确吗

  • 回复 正确,指向的就是自己本身
    作者 2018-08-20 18:45:10
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号