2017-10-13 90 views
0

我沒有收到任何錯誤,但我無法更新MySQL PHP。我想將下拉狀態從「sedang diproses」下拉列表更改爲「Berjaya或Tidak Berjaya」。此外,我無法在數據庫「sedang diproses」到「成功集團或Tidak成功集團」我無法更新MySQL PHP

改變這是我的代碼的HTML

<?php 
    session_start(); 
    include ('include/myFunction.php'); 
    require('include/connect.php'); 
?> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>Untitled Document</title> 
    </head> 
    <link href="css/myStyle.css" rel="stylesheet" type="text/css" /> 
    <link href="css/myStyle1.css" rel="stylesheet" type="text/css" /> 
     <!-- Button to open the modal login form --> 
     <link href="css/myStyle3.css" rel="stylesheet" type="text/css" /> 

    <body> 
    <div align="right"> 
     <a href="logout.php" ><img src="img/logout.png" width="63" height="46" /></a> 
    </div> 
    <div class="header" align="left"><a href="#"><img src="img/gmbar.PNG" width="223" height="126" /></a><!-- end .header --><!-- end .header --></div> 
    <div class="content" style="font:Verdana, Geneva, sans-serif"> 
    <div class="content" style="font:Verdana, Geneva, sans-serif"> 
    <div class="topnav" id="myTopnav" style="font-family:Verdana, Geneva, sans-serif"><a href="senaraipemohon.php">Kembali</a> 


    </div> 

    <p>&nbsp;</p> 
     <?php if($_SESSION['namaadmin'] ==null) 
     { 
     header('location:index.php'); 
     } 
     else 
     { 
      ?> 
      <form action="prosesstatus.php" method="post"> 
    <table width="1002" height="87" border="0" align="center" bgcolor="#CCCCFF"> 
     <tr bgcolor="#00CCFF"> 
     <td width="30"><strong>Bil</strong></td> 
     <td width="298"><strong>Nama</strong></td> 
     <td width="176"><strong>Nama Kursus</strong></td> 
     <td width="150"><strong>Tarikh Daftar</strong></td> 
     <td width="150"><strong>Status</strong></td> 
     <td width="168"><strong>Kemaskini Status</strong></td> 
     <td width="131"><strong>Pilihan</strong></td> 

     </tr> 
     <?php 
    $namakursus = ''; 
    if(isset($_GET['namakursus'])) { 
     $namakursus = $_GET['namakursus']; 
    } 

    $sql1 = "Select * from pemohonan INNER JOIN kursus ON pemohonan.idkursus = kursus.idkursus 
     INNER JOIN pemohon ON pemohonan.idPemohon = pemohon.idPemohon WHERE kursus.namakursus = '$namakursus' "; 
    $result1=mysqli_query($dbc,$sql1) or die (mysqli_error()); 
    $i=1; 
     while($row1 = mysqli_fetch_assoc($result1)) 
     { 
    ?> 
     <tr> 

     <td><strong><?php echo $i; ?><input name="idkursus" type="hidden" size="50" value="<?php echo $row1['idkursus'];?>"/><input name="idPemohonan" type="hidden" size="50" value="<?php echo $row1['idPemohonan'];?>"/></strong></td> 
     <td><strong><?php echo $row1['nama']; ?></strong><input name="id" type="hidden" size="50" value="<?php echo $row1['idPemohon'];?>"/></strong></td> 
     <td><strong><?php echo $row1['namakursus']; ?></strong></td> 
     <td><strong><?php echo $row1['tarikhpemohon']; ?></strong></td> 
     <td><strong><?php echo $row1['status']; ?></strong></td> 
     <td><select name="status" value="<?php echo $row1['status']; ?>"> 
       <option value="sila pilih">-Sila Pilih-</option> 
       <option value="Berjaya">Berjaya</option> 
       <option value="Tidak Berjaya">Tidak Berjaya</option> 
       </select></td> 

    <td><input name="btnKemaskini" type="submit" value="Kemaskini" /></td> 

     </tr> 




     <?php 

      $i++; 

     } 
     mysqli_close($dbc); 
     } 

     ?> 
    </table></form> 
    <p>&nbsp;</p> 
    <p>&nbsp;</p> 
    <div class="footer" style="font-family:Arial, Helvetica, sans-serif"> 
    <?php footertext(); ?> 

    </div> 
    </body> 
    </html> 

這是圖片 example

這是我自己的DB database

這是我的代碼的PHP

<?php 
require ('include/connect.php'); 

$idPemohonan = ''; 
$idPemohon = ''; 
$idkursus = ''; 
if (isset($_GET['idPemohon'],$_GET['idkursus'],$_GET['idPemohonan'])) 
{ 
$idPemohon = $_GET['idPemohon']; 
$idkursus = $_GET['idkursus']; 
$idPemohonan = $_GET['idPemohonan']; 
} 

$tarikhharini=date('y-m-d'); 
$status=$_POST['status']; 

$sql1 = "UPDATE pemohonan SET idPemohonan ='$idPemohonan' , idPemohon ='$idPemohon' , idkursus ='$idkursus' , tarikhpemohon ='$tarikhharini' , status='$status' 
where idPemohonan = '$idPemohonan' and idPemohon = '$idPemohon'"; 

$result1 = mysqli_query($dbc,$sql1) or die (mysqli_error()); 
$num_row1 = mysqli_affected_rows($dbc); 


    echo "<script language=\"JavaScript\">\n"; 
    echo "alert('Status Pemohonan Telah Dihantar!');\n"; 
    echo "window.location='senaraipemohon.php'"; 
    echo "</script>"; 


mysqli_close($dbc); 



?> 
+2

pleeaase ....停止混合標記+邏輯+數據庫操作...... _這是我的代碼Html_不,它不是!它是所有這些的混合 –

+1

您需要使用mvc架構來組織您的代碼。 – Akintunde007

回答

0

您的代碼不工作,因爲你沒有在 <form action="prosesstatus.php" method="post">

參數發送:

$idPemohon = $_GET['idPemohon']; $idkursus = $_GET['idkursus']; $idPemohonan = $_GET['idPemohonan'];

如果你想使用$ _GET鏈接應該是這樣的: prosesstatus.php?idPemohon=value&idkursus=value&idPemohonan=value

或者你應該添加這些參數在 輸入類型隱藏並在php中更改爲$ _POST

我同意別人比你應該使用MVC例如某種框架(Laravel,CodeIgniter) 或儘可能分開php和html,因爲你的代碼看起來不專業。 你的MySQL查詢很容易受到SQL注入,最有可能的文件

include/connect.php

不被外部公用文件夾這是不好的做法去做。

+0

感謝您的幫助..也許我還是初學者 – hasyif97

+0

非常抱歉,如果我犯了一些錯誤 – hasyif97