提交按钮将值传递给数据库

问题描述 投票:0回答:1

我编写了一个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>

插入部分,单独放置工作正常,但添加提交选项不工作,

请让我知道我错过了什么。

php submit isset
1个回答
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>

https://www.w3schools.com/PhP/php_forms.asp会给你一些想法

© www.soinside.com 2019 - 2024. All rights reserved.