PHP を使用してブログのような Web ページを作成するプロジェクトに取り組んでいます。フォームの上の画面にテキストを印刷したいのですが$_GET
、データが入力される前に変数がフォームからデータを取得しようとしているため、印刷できないようです。フォームの上にテキストを配置することは可能ですか?
これまでの私のコードは次のとおりです:(PHPは、「basic.php」(ファイル名)をタグのaction
属性に入れることで画面を更新します)<form>
<!-- this file is called basic.php-->
<!DOCTYPE html>
<html>
<head>
<title>My Blog</title>
<style type = "text/css">
h2
{
color:#FF2312;
text-align:center;
font-family:Impact;
font-size:39px;
}
p
{
font-family:Verdana;
text-align:center;
color:#000000;
font-size:25px;
}
</style>
</head>
<body>
<?php
$subject=$_GET["msg"];//variable defined but attempts to get unentered data
?>
<i> <?php print $subject;//prints var but gets error message because $subject can't get form data ?></i>
<!--want to print text above form-->
<form name = "post" action = "basic.php" method = "get">
<input type = "text" name = "msg">
<input type = "submit">
</form>
</body>
</html>