我无法更新MySQL PHP

时间:2017-10-13 15:09:34

标签: php mysql phpmyadmin

我没有收到任何错误,但我无法更新MySQL PHP。我想将“sedang diproses”下拉菜单中的下拉状态更改为“Berjaya或Tidak Berjaya”。另外我无法将数据库“sedang diproses”更改为“Berjaya或Tidak Berjaya”

这是我的Code 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

这是我的图像数据库 database

这是我的Code 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);



?>

1 个答案:

答案 0 :(得分: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

不在公共文件夹之外,这不是一个好习惯。