我已经附加了下面的代码。它是从用户界面接受值的表单,我想将结果保存在postgresql数据库中,但我的界面工作正常,但没有插入数据库中的值。
<?php
include("connection.php");
error_reporting(0);
?>
<html>
<head>
<title>TESTING INTERFACE</TITLE>
</head>
<body>
<BR>
TESTING INTERFACE
<BR>
<form action ="" method="GET">
Year <input type="text" name ="Year" value =""/><br><br>
GDP<input type="text" name ="GDP" value =""/><br><br>
Gross Indirect Tax <input type="text" name ="Gross_Indirect_Tax" value
=""/><br><br>
CE Revenue<input type="text" name =" CE_Revenue" value =""/><br><br>
CE Revenue percentage<input type="text" name ="CE_REvenue_Percentage"
value =""/><br><br>
<input type ="submit" name="" value ="submit"/>
</form>
<?php
$yr = $_GET['Year'];
$gs = $_GET['GDP'];
$rs1 = $_GET['Gross_Indirect_Tax'];
$rs2 = $_GET['CE_Revenue'];
$rs3 = $_GET['CE_REvenue_Percentage'];
echo $yr;
echo $gs;
echo $rs1;
echo $rs2;
echo $rs3;
//echo "$_POST[Year]";
$query = "INSERT INTO indirecttax
(Year,GDP,Gross_Indirect_Tax,CE_Revenue,CE_REvenue_Percentage)
VALUES($yr,$gs,$rs1,$rs2,$rs3)" ;
$x = pg_query($query);
//$qw = pg_query (INSERT INTO indirecttax
(Year,GDP,Gross_Indirect_Tax,CE_Revenue,CE_REvenue_Percentage)
VALUES($yr,$gs,$rs1,$rs2,$rs3)) ;
//$query = "INSERT INTO Criteria_Parameters
(CriteriaID,DomainID,Criteria_Name,Upper_Limit,Lower_Limit,Range,Unit)
VALUES
/*
$data = pg_query($conn,$qw);
if($data)
{
echo "data inserted into database";
}
else
{
echo "sorry";
}
*/
?>
</body>
</html>
我的connection.php文件工作正常。 我的insert语句没有给出结果
答案 0 :(得分:-1)
您似乎忘了将连接传递给pg_query
。
试试这个:
pg_query($conn, $query);
其中$conn
是您致电pg_pconnect