Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将表单发送到SQLdatabase(不允许使用405)_Php_Html_Mysql_Nginx - Fatal编程技术网

Php 将表单发送到SQLdatabase(不允许使用405)

Php 将表单发送到SQLdatabase(不允许使用405),php,html,mysql,nginx,Php,Html,Mysql,Nginx,我有一个网页: <head> <meta charset="utf-8"> <link rel="stylesheet" href="css/inputstyle.css"> <title>Database Input</title> </head> <body> <h1> Database Input Page </h1> <p> Here yo

我有一个网页:

<head>
  <meta charset="utf-8">
  <link rel="stylesheet" href="css/inputstyle.css">
  <title>Database Input</title>
</head>

<body>
    <h1> Database Input Page </h1>
    <p> Here you can input to the Database </p>
    <a href="View.html">View Database.</a>

    <form submit="submit.php" method="post">
        <p>First Name: <input type="text" name="firstname" /></p>
        <p>Surname: <input type="text" name="surname" /></p>
        <p>Age: <input type="text" name="age" /></p>
        <p><input type="submit" /></p>
    </form>
</body>


数据库输入
数据库输入页
您可以在这里输入到数据库

名字:

姓:

年龄:

这个php脚本:

<?php

$username="root";
$password="password";
$database="posts";
$firstname=$_POST['firstname'];
$surname=$_POST['surname'];
$age=$_POST['age'];
mysql_connect(serverip,$username,$password);
@mysql_select_db($database) or die( "Unable to connect to Database");
$query = "INSERT INTO input  
VALUES('$firstname','$surname','$age')";mysql_query($query);mysql_close();

?>
编辑:
你必须:(提交)


^^^^^^
将其更改为:(操作)



原始答复来自 POST变量区分大小写

你有:

  • 使用
    $firstname=$\u POST['firstname']调用

    这是错误的,原因有二

  • 它应该是
    $firstname=$\u POST['firstname']
  • 当前变量包含一个空格
你还有:

  • 使用
    $namese=$\u POST['namese']调用
哪一个应该是
$姓氏=$_POST['names']

然后

  • 它由
    $age=$\u POST['age']调用但是应该是
    $age=$\u POST['age']
这一行我不确定
mysql\u连接(serverip,$username,$password)
serverip
未定义


脚注:

mysql.*
函数弃用注意事项:

从PHP5.5.0开始,此扩展就不推荐使用,不建议用于编写新代码,因为它将在将来被删除。相反,应该使用或扩展名。在选择MySQL API时,请参阅以获取更多帮助

这些函数允许您访问MySQL数据库服务器。有关MySQL的更多信息,请访问»


MySQL的文档可以在»。

输入的表结构是什么?@Abhik Chakraborty表结构是-名字、姓氏、年龄,如果这是你的意思的话?是的,你有其他的COL,比如主键和all吗?请将整个结构发布到question.hmm上,可能是服务器配置错误,也可能在suject=>@dat_guy上阅读本文。我还删除了我的答案,因为您使用我的答案来更改变量。如果你在一个托管站点上,那么请与你的托管提供商联系。谢谢,我已经删除了这些变量的上限和空格;但我在提交表单时仍然会遇到“405不允许”错误。(还有,上面写着“serverip”的地方,我实际上只有我的服务器的ip,但我把它改为“serverip”只是为了提问——就像“密码”不是我的实际密码一样)请看我的Edit@dat_guy重新加载我的答案。谢谢,我试着将它从“提交”改为“操作”,但我仍然有同样的问题(错误405)另一件可能在这里起作用的事情是,你正在做
“插入输入值('$firstname','$names','$age')”
尝试使用实际列作为插入项,即:
“插入输入(firstname,姓氏,年龄)值('$firstname','$nam姓氏','$age')”
@dat\guy,具体取决于你的列名。另外,还要联系您的虚拟机提供商。我还注意到您正在使用
来“查看数据库”
.html
文件不会使用
.html
作为扩展来处理PHP/SQL,除非您指示Apache将
.html
视为PHP@dat_guy您所有的文件都设置为
.php
文件吗?
<form submit="submit.php" method="post">
      ^^^^^^
<form action="submit.php" method="post">