我编写了一个php代码,只要该页面加载,就需要将记录插入到表中。我编写了下面的脚本,它没有在数据库中插入任何内容。
<html>
<body>
<p align="center" ;">
<input type="submit" name="ReportCons_Submit" value="SUBMIT" style="font-family:Arial; font-weight:bold; font-size:14; color:rgb(32,46,125); letter-spacing:4; text-align:center; background-color:rgb(204,204,204); margin-left:0;" size="200">
</p>
<p align="center"><font face="Arial" color="navy"><span style="font-size:10pt;">
<?php
// This is in the PHP file and sends a Javascript alert to the client
$message = "Script begins";
echo "<script type='text/javascript'>alert('$message');</script>";
if ( isset($ReportCons_Submit)) {
// This is in the PHP file and sends a Javascript alert to the client
$message = "Connecting to Oracle";
echo "<script type='text/javascript'>alert('$message');</script>";
$conn = ocilogon("<USER>","<Pass>",'Local.com:1521/PRD');
// Insert the date into mytable
$s = oci_parse($conn,"insert into gem.my_table values ('EA','54896246','1521')");
// Insert & commits
$r = oci_execute($s);
// The rollback does nothing: the data has already been committed
// oci_rollback($conn);
// This is in the PHP file and sends a Javascript alert to the client
$message = "Data was committed";
echo "<script type='text/javascript'>alert('$message');</script>";
echo "Data was committed\n";
}
?>
</span></font></p>
</body>
</html>
插入部分,单独放置工作正常,但添加时提交选项不起作用,
请让我知道我错过了什么。
答案 0 :(得分:0)
您没有提交任何内容因为没有要提交的表单,并且您正在检查未定义的变量而不是发布到表单的值。对您的代码进行了一些更改。希望它现在可以正常工作
<html>
<body>
<p align="center" ;">
<form name="fff" method="get">
<input type="submit" name="ReportCons_Submit" value="SUBMIT" style="font-family:Arial; font-weight:bold; font-size:14; color:rgb(32,46,125); letter-spacing:4; text-align:center; background-color:rgb(204,204,204); margin-left:0;" size="200">
</p>
<p align="center"><font face="Arial" color="navy"><span style="font-size:10pt;">
</form>
<?php
// This is in the PHP file and sends a Javascript alert to the client
$message = "Script begins";
echo "<script type='text/javascript'>alert('$message');</script>";
if ( isset($_REQUEST['ReportCons_Submit'])) {
// This is in the PHP file and sends a Javascript alert to the client
$message = "Connecting to Oracle";
echo "<script type='text/javascript'>alert('$message');</script>";
$conn = ocilogon("<USER>","<Pass>",'Local.com:1521/PRD');
// Insert the date into mytable
$s = oci_parse($conn,"insert into gem.my_table values ('EA','54896246','1521')");
// Insert & commits
$r = oci_execute($s);
// The rollback does nothing: the data has already been committed
// oci_rollback($conn);
// This is in the PHP file and sends a Javascript alert to the client
$message = "Data was committed";
echo "<script type='text/javascript'>alert('$message');</script>";
echo "Data was committed\n";
}
?>
</span></font></p>
</body>
</html>