php get method problem
2018-08-20 17:50:34
0
7
1228

<?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?

reply all(6)
嘿哈

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 How to test? This code can get the value when running on other machines. . It doesn’t work on my machine.
    author 2018-08-21 18:23:02
  • reply It's impossible. Try running it on localhost.
    vec author 2018-08-22 12:58:03
vec

<?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方法 

vec

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

vec

Is

undefined index?


vec

What is the error message?

  • reply This code can get the value when running on other machines. . It doesn’t work on my machine.
    author 2018-08-21 18:23:31
  • reply I probably know the problem, maybe the file is not open. .
    author 2018-08-21 18:24:52
  • reply Got the problem, var_dump($file) returned false
    author 2018-08-21 18:28:56
好名字

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

  • reply Correct, it points to oneself
    author 2018-08-20 18:45:10
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template