如何使用PHP代码打印输入

时间:2016-05-01 05:10:31

标签: php html input output

我刚开始学习php和html,我想制作一些输入并用PHP代码打印输出的东西。但是,使用我的代码,它可以让我输入,但是当我点击提交时不打印任何内容。为什么呢?

<html>
<head><title>Noob</title></head>
<body>
<form action="" method="post">
<input type="text" name="username" value="" />
<input type="submit" name="submit value="Submit" />
</form>

<?php
 if (isset($_POST['submit'])) { //to check if the form was submitted
 $username= $_POST['username'];
 echo $username;
}
?>

</body>
<html>

5 个答案:

答案 0 :(得分:3)

在代码的下面一行

public partial class Form2 : Form
{
    public string newFirstName;
    public string newMiddleName;
    public string newLastName;
    public string newDOB;

    public Form2()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        int counter = 0;
        StreamReader getLength = new StreamReader("../../../patient info.txt");
        string lineInfo = getLength.ReadLine();

        while (lineInfo != null)
        {
            counter++;
            lineInfo = getLength.ReadLine();
        }
        getLength.Close();
        counter++;
        StreamWriter writeNewPatient = new StreamWriter("../../../patient info.txt", true );
        writeNewPatient.WriteLine("000" + counter + ", " + tbFirstName.Text + ", " + tbMiddleName.Text + ", " + tbLastName.Text + ", " + tbDOB.Text);
        writeNewPatient.Flush();
        writeNewPatient.Close();
        Form1 frm = new Form1();
        frm.pateintNumber.Add("000" + counter);
        frm.patientFirstName.Add(tbFirstName.Text);
        frm.patientMiddleName.Add(tbMiddleName.Text);
        frm.patientLastName.Add(tbLastName.Text);
        frm.patientDOB.Add(tbDOB.Text);
        frm.counter = frm.counter++;

        this.Close(); //to turn off current app
    }

    private void button2_Click(object sender, EventArgs e)
    {
        this.Close();
    }
} //end of program

单词name =&#34; submit没有结束双冒号

答案 1 :(得分:1)

您的HTML在

所在的行上缺少引号
{{link target=(concat '/' url)}}

应该是

<input type="submit" name="submit value="Submit" />

答案 2 :(得分:1)

您错过了按钮名称

中的引号
<html>
<head><title>Noob</title></head>
<body>
<form action="" method="post">
<input type="text" name="username" value="" />
<input type="submit" name="submit" value="Submit" />// you missed here
</form>

<?php
 if (isset($_POST['submit'])) { //to check if the form was submitted
 $username= $_POST['username'];
 echo $username;
}
?>

</body>
<html>

答案 3 :(得分:0)

语法错误您错过了双引号name =“submit”

    <?php
     if (isset($_POST['submit'])) { //to check if the form was submitted
    // For printing whole post data
     echo '<pre>'; print_r($_POST);
     $username= $_POST['username'];
     echo $username;
    }
    ?>

您也可以使用var_dump进行打印。 希望这会对你有所帮助。

答案 4 :(得分:0)

你确定通过php解释器运行页面吗? 在本地你可以使用xampp或wampp(产品由windows) 在Mac中你可以使用mampp