简体   繁体   English

我正在尝试将表单链接到我的PHP页面,当他单击“提交”按钮时,我想将用户的输入输出到该页面上

[英]I'm trying to link my form to my PHP page, and I want to print out the user's input onto that page when he clicks the submit button

I've tried using the method GET in my form, and $_GET in my PHP page, but it doesn't link both of them together. 我已经尝试过在表单中​​使用GET方法,在PHP页面中使用$ _GET方法,但是它没有将两者链接在一起。 I want to print out the elements in the form inputted by the user when the user clicks the submit button. 我想在用户单击提交按钮时以用户输入的形式打印出元素。 Here is the code I used for my form: 这是我用于表单的代码:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MY Form</title>
</head>
<body>
    <form action="q4.php" method="get">

      <label><b>First Name:</b></label><br />
      <input type="text" name="first_name"><br />
      <label><b>Last Name:</b></label><br />
      <input type="text" name="second_name">

        <br>

        <label for="status">Status</label><br>
        <select name="status" id="status">
        <option value="undergraduate">UnderGraduate</option>
        <option value="postgraduate">Postgraduate</option>
        <option value="alumni">Alumni</option>
        </select>
        <br><br><br>

        <input type="radio" name="continuing">Continuing<br>
        <input type="radio" name="continuing">Not Continuing<br>

        <br><br>
        <label>Satisfaction Level <br></label>
        <label>0</label><input type="range" name="satisfaction" min="0" max="100"/><label>100</label>
        <br><br>
        <input type="submit" value="Submit">
    </form>
</body>
</html>

Here's the code I used for my PHP: 这是我用于PHP的代码:

<?php
$names = array(first_name => '', second_name => '');

reset($names);
while (list($key, $val) = each($names)) {
    echo "$key => $_GET\n";
}
?>

If you want to print out all results you could just do something like 如果要打印所有结果,可以执行以下操作

<?php
foreach($_GET as $key => $value){
echo $key.": ".$value;
}
?>

But if you would rather only show specific data then perhaps something like this 但是,如果您只希望显示特定数据,那么可能是这样的

<?php
$names = array(first_name => '$_GET['first_name']', second_name => 'second_name');

foreach($names as $name => $value){
echo $name.": ".$value;
}
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在PHP中,我如何将表单数据发送到页面,但是当用户单击“提交”按钮时却将用户定向到另一个页面? - In PHP how do I send form data to a page but direct the user to another when he clicks the submit button? 当用户进入主页(index.php)时,如何显示用户随机子网页? - How can I show the user random subwebpage when he enters my main page (index.php)? 当我提交表单输入类型=文件以使用 php 发送图像时,我想重定向到另一个页面 - when i submit form input type=file for send image with php i want redirect to an other page 当用户单击注销并重定向到主页时,我想加载一个gif图像。 我正在尝试使用php - I want to load a gif image when user clicks on logout and then redirects to home page. i am trying to do using php 我希望我的php表单提交数据并在同一页面上重定向,但选项卡不同 - I want my php form to submit data and redirect on the same page but different tab 我希望我的 html 页面在我提交某个输入时重定向到另一个 html 页面我该怎么做 - I want my html page to redirect to another html page when I submit a certain input how can i do that 当我在php表单上单击Submit时,登录页面变为空白,并且它不向数据库提交日期 - When I click submit on my php form the landing page comes up blank and it does not submit date to the database 当我使用jQuery AJAX在页面上提交tinyMCE表单时,需要两次单击才能实际提交到数据库 - When I use jQuery AJAX to submit tinyMCE forms on my page, it takes two clicks to actually submit to database 我正在尝试将2个按钮放入样式div中,但我希望其中一个按钮处于我拥有的表单中,而另一个按钮处于提交表单之外 - I'm trying to put my 2 buttons in my styling divs but I want one of the buttons to be in a form I have and the other outside the submit form 我的 PHP 表单的显示页面出现错误 - I'm getting an error in the Display page of my PHP form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM