我试图将表单中的数据插入到通过ODBC连接的Server数据库表中。在我提交数据之后,它将显示为一个空白行,其中只有具有值的ID。我对PHP非常陌生,并从教程中获得了部分代码。这只是个测试项目。下面是代码:
<html>
<header>
<title>
</title>
</header>
<body>
<form action="\INSERTCODE.php" method="POST">
<input type= "number" step="any" name="sepal_lengp" placeholder="Sepal Length">
<input type= "number" step="any" name="sepal_widthp" placeholder="Sepal Width">
<input type= "number" step="any" name="petal_lengp" placeholder="Petal Length">
<input type= "number" step="any" name="petal_widthp" placeholder="Petal Width">
<input type= "text" name="flower_type" placeholder="Flower Name">
<button type="submit" name="submit" >INPUT VALUES</button>
</form>
<?php
//display all results from table
include("C:\Users\Dshop\Desktop\php-7.3.3\Server1\connection.php");
$i=1;
$sql = "SELECT * FROM dbo.textcsv";
$result = odbc_exec( $connection, $sql );
while($all =odbc_result_all($result,$i) ){
echo $all;
}
?>
</body>
</html>这一部分包括表格。文件名是index1.php。
<?php
include("C:\Users\Dshop\Desktop\php-7.3.3\Server1\connection.php");
$sepal_lengp = $_POST['sepal_lengp']??'';
$sepal_widthp = $_POST['sepal_widthp']??'';
$petal_lengp = $_POST['petal_lengp']??'';
$petal_widthp = $_POST['petal_widthp']??'';
$flower_typep = $_POST['flower_typep']??'';
$dbinsert = "INSERT INTO dbo.textcsv (sepal_leng, sepal_width, petal_leng, petal_width, flower_type) VALUES ('$sepal_lengp', '$sepal_widthp', '$petal_lengp', '$petal_widthp', '$flower_typep');";
odbc_exec( $connection, $dbinsert );
HEADER("Location: ../index1.php?=success");这一部分将数据插入到数据库表中,使用$_POST从index1.php获取数据。这个文件名为INSERTCODE.php。$connection和connection.php是包含到ODBC连接的文件。

对于这个测试项目,我使用了Iris数据集。我认为我必须使用ODBC和Server,而不是mysql。server是2014年版,PHP7.33,使用node.js运行服务器。我们非常感谢你的帮助!
编辑我发现$_POST没有从表单中获取任何值。有什么想法吗?
编辑2我尝试过使用$_REQUEST,检查var_dump,并做了所有这些事情,但我仍然一无所获。在转到forms.asp获取一个示例表单后,我发现这个示例也不起作用。现在,我不确定问题是来自于代码,还是来自于php配置。需要帮助,请帮忙。
发布于 2019-03-29 14:28:42
在将我的问题重新表述为"node.js不获取post数据“之后,我发现了这个问题。Node.js需要额外的步骤来处理POST数据。因此,由于这个原因,我的输入被node.js忽略了,INSERTDATA.php运行时没有任何数据来插入任何内容。问题的解决方案是使用类似于body解析器或其他solution from another question的东西。
我采取的解决方案是卸载node.js并使用XAMPP。使用起来容易多了。
还有谁能提醒我的问题是重复的吗?
https://stackoverflow.com/questions/55301897
复制相似问题