用php文件连接wordpress上的表单页面

用php文件连接wordpress上的表单页面,php,wordpress,forms,postgresql,Php,Wordpress,Forms,Postgresql,我在wordpress的一页上创建了表单: <form action="scores_send.php" method="post"> <strong>Date: </strong><input type="date" name="date" /><br /> <strong>TEAM 1:</strong> Player 1.: <input type="text" name="team1_player

我在wordpress的一页上创建了表单:

<form action="scores_send.php" method="post">
<strong>Date: </strong><input type="date" name="date" /><br /> 
<strong>TEAM 1:</strong>
Player 1.: <input type="text" name="team1_player1" /><br /> 
Player 2.: <input type="text" name="team1_player2" /><br /> 
<strong>TEAM 2:</strong>
Player 1.: <input type="text" name="team2_player1" /><br /> 
Player 2.: <input type="text" name="team2_player2" /><br /> 
<strong>SCORE:</strong>
Team 1. <input type="number" name="score_team1" min="0" max="5"/> : <input type="number" name="score_team2"  min="0" max="5"/> Team 2.<br /> 
<input type="submit" value="Add" /> 
</form>

日期:
第一组: 播放器1.:
播放器2.:
第二组: 播放器1.:
播放器2.:
得分: 第一队:第二小组。
我还编写了php代码,连接到我的外部(无wordpress)postgres数据库(代码中的连接参数不正确),并将表单中的信息插入到一个表中:

<?php
$date = $_POST['date']; 
$t1p1 = $_POST['team1_player1']; 
$t1p2 = $_POST['team1_player2'];
$t2p1 = $_POST['team2_player1']; 
$t2p2 = $_POST['team2_player2'];
$score1 = $_POST['score_team1'];
$score2 = $_POST['score_team2'];

if($date and $t1p1 and $t1p2 and $t2p1 and $t2p2 and $score1 and $score2) { 

    $connection = pg_connect("host=127.0.0.1 port=5432 dbname=scores user=user password=pass")
    or die('Brak polaczenia z serwerem PostgreSQL'); 
    $db = @pg_select_db('scores', $connection) 
    or die('Nie moge polaczyc sie z baza danych'); 

    $team1 = @pg_query("INSERT INTO scores.games (score_team1, score_team2, datetime, team1_player1, team1_player2, team2_player1, team2_player2) VALUES ('$score1', '$score2', '$date', '$t1p1', '$t1p2', '$t2p1', '$t2p2'"); 

    if($team1) echo "Scores added."; 
    else echo "ERROR! Scores not added"; 
     pg_close($connection); 
} 
?>
您应该在表单操作中使用

其中page slug是通过将scores_send.php作为模板创建的另一个页面的slug。它会将所有表单值发布到scores_send.php。您可以从中进一步插入外部数据库

<form action="http://example.com/page-slug/" method="post">

只需将表单的操作更改为:

确保您的scores_send.php位于安装的根目录上

因此,您的表单如下所示:

<form action="http://yoursite.com/scores_send.php" method="post">


使用($date&&$t1p1&&$t1p2&&$t2p1&&$t2p2&&$score1&&$score2)而不是“如果($date and$t1p1 and$t1p2 and$t2p1 and$t2p2 and$score1 and$score2)”或者如何使用?我对PHP了解不够;)我尝试了您的方法,在表单浏览器中单击“添加”后显示空白页面,在数据库中未添加任何内容。也许这是我的PHP代码的问题?我也尝试了你的方法,它与Sunil Chaudhary的方法中的情况相同-空白页,没有向我的数据库添加任何内容:(首先需要选中get_header()和get_footer())函数在您的目标页面中,如果它不在那里,它将使您的页面变为空白。另外,您需要测试“echo”,还需要测试“echo”post值,以交叉检查目标值以及表单是否实际发布。如果这样做无法得到结果,请尝试使用Ajax方法获取post表单值,然后从中插入数据库。