简单的网络表单PHP脚本-它没有';不起作用


simple webform PHP script - it doesn't work

我希望Php脚本将它从html页面获得的所有值打印到屏幕上。

这是HTML代码:

  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255">
<title>Insert title here</title>
</head>
<body>
   <div>
    <form enctype="multipart/form-data" action="rect.php" method="post">
        <label>Name:</label><input type="text" name="name"><br />
        <label>Family Name:</label><input type="text" name="family"><br />
        <label>Age:</label><input type="text" name="age"><br />
        <input type="button" value="Print">
    </form>
   </div>
</body>
</html>

//这是PHP代码:

    <?php 
$name = $_REQUEST['name'];
$family_name = $_REQUEST['family'];
$age = $_REQUEST['age'];
print $name.$family_name.$age;
?>

$_REQUEST应该可以工作,但是您的按钮是无用的。

    <input type="button" value="Print"> 

应该是

    <input type="submit" value="Print">

这样就可以了:)

首先:使用$_POST。使用$_REQUEST是不好的做法。

<?php 
   $name = $_POST['name'];
   $family_name = $_POST['family'];
   $age = $_POST['age'];
   print $name.$family_name.$age;
?>

而且你的按钮无法提交。这样做:

<input type="submit" value="Print">

更改

<input type="button" value="Print">

<input type="submit" value="Print">

如果您只是向PHP表单发送文本,则不需要enctype。

您的按钮必须是type="submit"

你应该使用$_POST,因为很明显你在表单中使用了它。