2017-12-22 23 views
0

나는 페이지가로드 될 때마다 테이블에 레코드를 삽입해야하는 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

성공적으로 연결을 설정할 수를 줄 것이다? $ conn를 echo 한 후 1을 확인해보십시오 – Abhinav

+0

제출 버튼을 누른 후에 PHP 세그먼트를 실행 하시겠습니까, 아니면 버튼을 이전에 누르면 동일한 페이지에 놓으시겠습니까? –

+0

@Abhinav 루프 자체에 들어 가지 않습니다. 일단 들어 오면 "Connecting to Oracle"이라는 창이 나타납니다. if 문 본문은 별도의 스크립트에 넣으면 완벽하게 작동합니다. 하지만 여기서 일하는게 아니야. –

답변

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는 당신에게 몇 가지 아이디어