如何使用php更新postgresql行?

| 首先,我想说我是Postgresql和php的初学者。我的公司告诉我创建一个可以在本地服务器上查看和编辑的数据库..所以我在postgresql中创建了数据库。数据库:
<html>
<head>
<title>Ongoing projects</title>
</head>
<body bgcolor=\"666657\">
<?php
//database access information
require_once(\"DB.php\");
$host = \"localhost\";
$user = \"admin\";
$pass = \"\";
$db = \"Project_list\";
$port = \"5432\";

//open a connection to the database server
$connection = pg_connect(\"host=$host dbname=$db user=$user password=$pass port=$port\");
if (!$connection)
{
die(\"Could not open connection to database server\");
}

?>


<?php


$query = \'select * from ongoing\';
$result = pg_query($query); $i = 0;


echo \'<html><table bgcolor=\"666657\" width=\"10\" height=\"30\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><td align=\"center\"> <h1><font color = \"#ffb200\"> Ongoing projects</h1>\';

 echo \'<html><body><table border= 2 BORDERCOLOR=\"000000\" cellpadding=\"1\" cellspacing=\"0\"> <tr >\';


while ($i < pg_num_fields($result)) {
$fieldName =pg_field_name($result, $i);
echo \'<b>\'.\'<td width=\"2\" bgcolor=\"666657\" align=\"center\">\'.\'<font color = \"#ffb200\">\'. \'</b>\'.\'<b>\'. $fieldName . \'</b>\'. \'</td>\';
$i = $i + 1; }
 echo(\"<td><align= center><font color = #ffb200><b>Action</td>\");

echo \'</tr>\' ;
$i = 0;

while ($row = pg_fetch_row($result)) {
echo \'<tr align=\"center\" width=\"1\">\';
$count = count($row);
$y = 0;
while ($y < $count) {
$c_row = current($row);
echo \'<td>\' .\'<font color = \"#ffb200\">\'. $c_row . \'</td>\';

next($row);

$y = $y + 1;
}
echo(\"<td><align= center><a href=\'editongoing.php?ProjectID=\".$row[0].\"\'>Edit</a></td>\");
echo \'</tr>\';
$i = $i + 1;
}


pg_free_result($result);

echo \'</table></body></html>\';

?>
<h3>
<a href=\"projects.php\"</a>Back to projects page</a>

</h3>
<SCRIPT LANGUAGE=\"JavaScript\">
if (window.print) {

document.write(\'<form> \'
+ \'<input type=button name=print value=\"Click\" \'
+ \'onClick=\"javascript:window.print()\"> To Print!</form>\');
}
// End -->
</script>
当您单击编辑按钮时,您将转到此页面,您可以在其中编辑所需的原始代码,这是(编辑)代码:
<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\">
<html>
<head>
<title>Edit Ongoing projects</title>
</head>
<body bgcolor=\"666657\">

<?php
// attempt a connection
$connection = pg_connect(\"host=localhost dbname=Project_list user=admin password=\");
if (!$connection) {
die(\"Error in connection: \" . pg_last_error());
}
if ($_REQUEST[\'ProjectID\']!=\'\'){

$QueryStr = \"Select * from ongoing where project_no=\'\".$_REQUEST[\'ProjectID\'].\"\'\";
$result = pg_query($connection, $QueryStr);
if (!$result) {
die(\"Error in SQL query: \" . pg_last_error());
}
$row = pg_fetch_row($result);

print_r($row);

}
if ($_POST[\'submit\']) {


// escape strings in input data
$project_no = pg_escape_string($_POST[\'project_no\']);
$title = pg_escape_string($_POST[\'title\']);
$duration = pg_escape_string($_POST[\'duration\']);
$manager = pg_escape_string($_POST[\'manager\']);
$country = pg_escape_string($_POST[\'country\']);
$total_fee = pg_escape_string($_POST[\'totalfee\']);
$performed = pg_escape_string($_POST[\'performed\']);
$remaining = pg_escape_string($_POST[\'remaining\']);
$gross_profit = pg_escape_string($_POST[\'gross_profit\']);
$gp = pg_escape_string($_POST[\'gp\']);
$performance_year = pg_escape_string($_POST[\'performance_year\']);
$gp_year = pg_escape_string($_POST[\'gp_year\']);


// execute query
$sql = \"INSERT INTO ongoing (project_no, project_title, duration, manager, country, total_fee,
performed, remaining, gross_profit, gp, performance_year, gp_year)
VALUES(\'$project_no\', \'$title\', \'$duration\', \'$manager\', \'$country\',\'$total_fee\',\'$performed\',\'$remaining\',
\'$gross_profit\',\'$gp\', \'$performance_year\',\'$gp_year\')\";
$result = pg_query($connection, $sql);
f (!$result) {
die(\"Error in SQL query: \" . pg_last_error());
}

echo \"Data successfully inserted!\";


// free memory
pg_free_result($result);

// close connection
pg_close($connection);
}
?>

<form action= \"<?php echo $_SERVER[\'PHP_SELF\']; ?>\" method=\"post\"><b><font color = \"#ffb200\">
Project No.: <br>  <input id=\"project_no\" type=\"text\" name=\"project_no\" size=\"20\" value=<?= $row[0] ?>>
<p>
Project Title: <br> <input id=\"title\" type=\"text\" name=\"title\" value=\'<?= $row[1] ?>\'>
<p>
Duration: <br> <input ID=\"duration\" type=\"text\" name=\"duration\" value=<?= $row[2] ?>>
<p>
Project Manager: <br> <input ID=\"manager\" type=\"text\" name=\"manager\" value=<?= $row[3] ?>>
<p>
Country: <br> <input ID=\"country\" type=\"text\" name=\"country\"  value=<?= $row[4] ?>>
 <p>
Total Fee: <br> <input ID=\"totalfee\" type=\"text\" name=\"total_fee\" value=<?= $row[5] ?>>
 <p>
Already performed: <br> <input ID=\"performed\" type=\"text\" name=\"performed\" value=<?= $row[6] ?>>
 <p>
Remaining performance: <br> <input ID=\"remaining\" type=\"text\" name=\"remaining\" value=<?= $row[7] ?>>
 <p>
Gross Profit: <br> <input ID=\"gross_profit\" type=\"text\" name=\"gross_profit\" value=\'<?= $row[8] ?>\'>
<p>
GP%: <br> <input ID=\"gp\" type=\"text\" name=\"gp\" value=<?= $row[9] ?>>
<p>
Performance actual year: <br> <input ID=\"performance_year\" type=\"text\" name=\"performance_year\" value=<?= $row[10] ?>>
<p>
GP actual year: <br> <input ID=\"gp_year\" type=\"text\" name=\"gp_year\" value=<?= $row[11] ?>>
<p>

<input type=\"submit\" name=\"submit\" value=\"Sumbit my table\" size=\"30\">

<P>
<a href=\"ongoing.php\"</a>View ongoing projects</a>
<a href=\"editproject.php\"</a>Back to editing menu</a>
</form>

</body>
</html>
我的问题是,当我编辑数据并单击“提交我的表”时,将插入一个新的原始文件。但是我希望它不被更新而被更新... help plz     
已邀请:
        您需要选择要更新的记录(标识号),然后查询将如下所示
$sql = \"UPDATE ongoing SET field1=\'value\', field2=\'value\' ... WHERE id = \'id of project you want to edit\'\";
    

要回复问题请先登录注册