我正在嘗試爲棒球數據庫創建一個Web界面,但是當我將信息輸入表單並按提交時,它總是會出現'發生錯誤'。 以下是帶有表單的網頁。PHP PSQL插入錯誤
<html>
<?php
$dbconn = pg_connect("dbname=mine user=mine password=mine");
if ($dbconn) {
echo "Connection established <br/>";
}
echo "Here are the current NL West Teams <br/>";
$result = pg_query($dbconn, "SELECT Name, Record FROM Teams");
if (!$result) {
echo "An error occurred.\n";
exit;
}
while ($row = pg_fetch_row($result)) {
echo "Team: $row[0] Record: $row[1]";
echo "<br />\n";
}
?>
<form action="InsertPP.php" method="post">
Name: <input type="text" name="name"><br>
Team: <input type="text" name="team"><br>
Number: <input type="text" name="number"><br>
Handed: <input type="text" name="Handed"><br>
Position: <input type="text" name="Position"><br>
<input type="submit">
</form>
</html>
這裏是插入PHP腳本。
<html>
<body>
<?php
$dbconn = pg_connect("dbname=mine user=mine password=mine");
if ($dbconn) {
echo "Connection established <br/>";
}
$_first = $_POST["Handed"];
$_second = $_POST["Position"];
$_third = $_POST["name"];
$_fourth = $_POST["number"];
$_fifth = $_POST["team"];
$Query = pg_query(dbconn, "INSERT INTO PosPlayer VALUES('$_first', '$_second', '$_third', $_fourth, '$_fifth)'");
if (!$Query) {
echo "An error occurred.\n";
exit;
}
echo "Your Player has been added!";
?>
</body>
</html>
我輸入相同的價值觀向Postgres和形式,玩家在Postgres的直接創建,但是當輸入發生到表單中的一些錯誤。有任何想法嗎?
編輯:我修復了在dbconn前缺少的$。仍然收到'發生錯誤'。
您應該使用錯誤報告來診斷錯誤。我會從'dbconn'開始'$'開始。在這裏'pg_query(dbconn,'< - 看它..這個代碼也會打開你到SQL注入。我不熟悉'postgresql',但我想有一個驅動程序支持參數化查詢;我推薦 – chris85
這是一個語法錯誤 –
請檢查您的網絡服務器的error.log文件是否存在* actual *錯誤訊息 –