我的PHP代码不起作用?

时间:2022-11-22 21:28:31

My basic php echo is not functioning correctly? Its simply one line and i did not think it was wrong. If someone could please give me some pointers that would be great. Here is my code:

我的基本php回声功能不正常?它只是一行,我不认为这是错的。如果有人可以请给我一些很棒的指示。这是我的代码:

HTML:

HTML:

<form id ="myForm" action ="register.php" method="post">
    <h3>Create Username</h3>
    <input type="text" name="username">
    <h3>Create Password</h3>
    <input type ="password" name="password" id ="passwordBoxOne">
    <h3>Confirm Password</h3>
    <input type ="password" id ="passwordBoxTwo">
    <h3>Email</h3>
    <input type ="email" name="email"><br>
    <input type ="submit" value="Register" id="submitButton">
</form>

register.php:

register.php:

<?php echo $_POST["username"];?>

When i run this code which is on a web server then nothing appears on the screen. I was assuming that the value in the username input would appear.

当我运行Web服务器上的此代码时,屏幕上不会显示任何内容。我假设用户输入中的值会出现。

3 个解决方案

#1


2  

So the issue is that your hosted code is not the same as your pasted code here. Using inspect element on the link you provided, you have not set the method attribute of the form element. By default, this is GET.

所以问题是您的托管代码与此处的粘贴代码不同。在您提供的链接上使用inspect元素,您尚未设置表单元素的method属性。默认情况下,这是GET。

Add method="POST" to your form element.

将method =“POST”添加到表单元素。

#2


0  

In the first line of the example code you posted here you wrote method="post" which is right but you probably forgot to write it also in the code on your page. If you try to use the form you can see in the url that the GET method is used instead. In order to work just add to the first line of the form the attribute method with value post like that:

在您在此处发布的示例代码的第一行中,您编写了method =“post”,这是正确的,但您可能忘记在页面上的代码中编写它。如果您尝试使用表单,则可以在URL中看到使用GET方法。为了工作,只需添加到表单的第一行,使用值post的属性方法:

<form id="myForm" action="register.php" method="post">

#3


-1  

If

如果

echo $_POST["username"];

does not produce any output, it means that $_POST["username"] either does not exist and your error reporting settings suppress warnings, or is an empty string. It does not mean that echo is broken.

不会产生任何输出,这意味着$ _POST [“username”]不存在,您的错误报告设置会禁止警告,或者是一个空字符串。这并不意味着回声被打破。

Assuming your PHP error log does not hint at any problems, the next step is to dump $_POST, e.g. through a

假设您的PHP错误日志没有提示任何问题,下一步是转储$ _POST,例如通过

print_r ($_POST); die;

on the first line of register.php. If that's empty, take it from there.

在register.php的第一行。如果那是空的,那就从那里拿走它。

#1


2  

So the issue is that your hosted code is not the same as your pasted code here. Using inspect element on the link you provided, you have not set the method attribute of the form element. By default, this is GET.

所以问题是您的托管代码与此处的粘贴代码不同。在您提供的链接上使用inspect元素,您尚未设置表单元素的method属性。默认情况下,这是GET。

Add method="POST" to your form element.

将method =“POST”添加到表单元素。

#2


0  

In the first line of the example code you posted here you wrote method="post" which is right but you probably forgot to write it also in the code on your page. If you try to use the form you can see in the url that the GET method is used instead. In order to work just add to the first line of the form the attribute method with value post like that:

在您在此处发布的示例代码的第一行中,您编写了method =“post”,这是正确的,但您可能忘记在页面上的代码中编写它。如果您尝试使用表单,则可以在URL中看到使用GET方法。为了工作,只需添加到表单的第一行,使用值post的属性方法:

<form id="myForm" action="register.php" method="post">

#3


-1  

If

如果

echo $_POST["username"];

does not produce any output, it means that $_POST["username"] either does not exist and your error reporting settings suppress warnings, or is an empty string. It does not mean that echo is broken.

不会产生任何输出,这意味着$ _POST [“username”]不存在,您的错误报告设置会禁止警告,或者是一个空字符串。这并不意味着回声被打破。

Assuming your PHP error log does not hint at any problems, the next step is to dump $_POST, e.g. through a

假设您的PHP错误日志没有提示任何问题,下一步是转储$ _POST,例如通过

print_r ($_POST); die;

on the first line of register.php. If that's empty, take it from there.

在register.php的第一行。如果那是空的,那就从那里拿走它。