HTML 表单充当 get 而不是 post [英] HTML form acting as get instead of post
问题描述
我对整个 PHP/HTML 交易还很陌生,但遇到了一个我不知道如何解决的问题.这是一个非常简单的表单,可让您将数据输入到数据库中.PHP代码如下:
I'm pretty new to the whole PHP/HTML deal, and I've run into a problem that I don't know how to fix. It's a pretty simple form that lets you enter data into database. The PHP code is as following:
<?
include("../sqlcontext.php");
$foo = mysql_query("SELECT*FROM users WHERE checksum='".$_COOKIE['userCookie']."'");
if($_COOKIE['userCookie'] == '' || !mysql_num_rows($foo)){
echo 'Du er ikke logget ind :( <a href="login.php">log ind her</a>';
}
else{
if($_POST['genreKnap']){
$nameGenre = $_POST['nameGenre'];
$textGenre = $_POST['textGenre'];
$succes = mysql_query("INSERT INTO genre VALUES('null','$nameGenre','$textGenre')");
if($succes){
echo 'Yay!';
}else {
echo 'Oh no';
}
}
?>
表格如下:
<form name="form1" method="post" enctype="text/plain" action="">
<table>
<tr>
<td>Genre navn:</td>
<td><input type="text" name="nameGenre" id="nameGenre" style="width:100%; padding-right: 1px" /></td>
</tr>
<tr>
<td>Genre beskrivelse:</td>
<td><textarea name="textGenre" id="textGenre" style="width:100%; padding-right: 1px"></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="genreKnap" id="genreKnap" value="Go!"/></td>
</tr>
</table>
</form>
每当我按下提交按钮时,它就好像它是一个 get 方法而不是一个 post.
Whenever I press the submit button, it seems as though it acts as if it was a get method and not a post.
推荐答案
啊哈!!!
您没有正确发布表单.设置
You are not posting the form correctly. Set the
action=""
到
action="code.php"
假设您的 php 页面名为 code.php.只需将其更改为php页面的名称/路径,表单就会将数据发送到您的php代码中进行处理.
Assuming your php page is called code.php. Just change it to the name/path of the php page and the form will send the data to your php code to process.
当您将 action=""
留空时,它会将数据发布到自身(同一页面).它不是作为 GET,它仍然作为 POST,但张贴到错误的地方.我认为你把问题的标题写错了.
When you leave action=""
to blank, it posts the data to itself (the same page). It is not acting as GET, it is still acting as POST, but posting to the wrong place. I think you worded the title of the question wrong.
你的意思是它表现得像 get 而不是 post.你不能在你的 PHP 中读取 $_POST 变量吗?
What do you mean it is acting like get instead of post. Can you not read $_POST variables in your PHP?
删除表单代码中的 'enctype="text/plain"'
.
这篇关于HTML 表单充当 get 而不是 post的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!