search

Home  >  Q&A  >  body text

php get method problem

<?php

echo '<h1>Message area</h1>';

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


echo 'Username:<input type="text" name="username" /><br />';

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

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

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');



##?>

Why can’t I receive the $username and $content variables in the form?

2329 days ago1277

reply all(7)I'll reply

  • 嘿哈

    嘿哈2018-08-21 17:30:10

    I took your code and tested it locally. I can receive the parameters. I will test step by step to see where the problem is.

    reply
    0
  • How to test? This code can get the value when running on other machines. . It doesn’t work on my machine.

    · 2018-08-21 18:23:02
    vec

    It's impossible. Try running it on localhost.

    vec · 2018-08-22 12:58:03
  • vec

    vec2018-08-21 10:00:15

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

    reply
    0
  • vec

    vec2018-08-21 09:54:37

    No problem with passing value. I tested it locally but the echo data should be wrong

    reply
    0
  • vec

    vec2018-08-21 09:46:06

    Is

    undefined index?


    reply
    0
  • vec

    vec2018-08-21 09:45:21

    What is the error message?

    reply
    0
  • This code can get the value when running on other machines. . It doesn’t work on my machine.

    · 2018-08-21 18:23:31

    I probably know the problem, maybe the file is not open. .

    · 2018-08-21 18:24:52

    Got the problem, var_dump($file) returned false

    · 2018-08-21 18:28:56
  • 好名字

    好名字2018-08-20 18:43:39

    Are you sure the action in your form points to the correct direction?

    reply
    0
  • Correct, it points to oneself

    · 2018-08-20 18:45:10
  • Cancelreply