I have 2 user which is officer and admin. The officer fill in the form. Admin will open the form, see details of officer and fill his detail. The problem is i success output all the information fill by the officer but when the admin fill the data not in the same row as officer data in database. Here my code:

lihatpemohon.php:

<?php
session_start();
include('db_connection.php');

    $view_id=$_GET['get'];  
    $view_query="SELECT * FROM permohonan WHERE id='$view_id'"; 
    $run=mysqli_query($dbcon,$view_query);  
    while($row=mysqli_fetch_array($run))
    {  

        echo"Kepada :<input type='text' name='kepada' value='".$row['kepada']."' /><br><br>";
        echo'<br>Tuan,<br> <b><h4>MEMOHON KEBENARAN MENINGGALKAN PEJABAT OLEH PEGAWAI/KAKITANGAN BAHAGIAN TEKNOLOGI PENDIDIKAN NEGERI PERAK DAN RANGKAIAN</h4></b><br>';
        echo"Saya :    <input type='text' name='nama' value='".$row['nama']."' /><br><br>";
        echo"Jawatan :<input type='text' name='jawatan' value='".$row['jawatan']."' /><br><br>";
        echo"Pada :<input type='date' name='tarikh1' value='".$row['tarikh1']."' /><br><br>";
        echo"Dari jam :<input type='time' name='jam1' value='".$row['jam1']."' /><br><br>";
        echo"Hingga jam :<input type='time' name='jam2' value='".$row['jam2']."' /><br><br>";
        echo"Kerana :<input type='text' name='kerana' value='".$row['kerana']."' /><br><br>";
        echo"Tarikh :<input type='date' name='tarikh2' value='".$row['tarikh2']."' /><br><br>";
        echo"Nama Pemohon :<input type='text' name='nama2' value='".$row['nama2']."' /><br><br>";
        echo"Jawatan :<input type='text' name='jawatan2' value='".$row['jawatan2']."' /><br><br>";
    }  

?> <hr> <form role="form" method="post" action="lihatpemohon.php"> <div class="form-group"> <select name="mohon"> <option value="Diluluskan">Diluluskan</option> <option value="Tidak Diluluskan">Tidak Diluluskan</option> </select> </div> <div class="form-group">
                            Kepada :<select name="nama3"> <option value="MOKHTAR">Mokhtar</option> <option value="AZMAN">Azman</option> <option value="SHARUDDIN">Sharuddin</option> </select> </div> <div class="form-group">  
                                Jawatan :    <input style="width: 600px" placeholder="Ketua Pusat Kegiatan Guru/Ketua Unit/Ketua Penolong Pengarah" type="text" name="jawatan3" > </div> <div class="form-group">  
                                Tarikh :    <input style="width: 600px" placeholder="Ketua Pusat Kegiatan Guru/Ketua Unit/Ketua Penolong Pengarah" type="date" name="tarikh3"> </div> <br> <input class="btn btn-lg btn-success btn-block" type="submit" value="Update" name="adminmasuk" > </form> <?php  

if(isset($_POST['adminmasuk']))  
{  
    $view_id=$_POST['get'];
    $mohon=$_POST['mohon'];  
    $nama3=$_POST['nama3']; 
    $jawatan3=$_POST['jawatan3']; 
    $tarikh3=$_POST['tarikh3'];  

    if($mohon=='')  
    {  
        //javascript use for input checking  
        echo"<script>alert('Sila pilih Diluluskan/Tidak Diluluskan')</script>";  
    exit();//this use if first is not work then other will not show  
    }  

    if($nama3=='')  
    {  
        echo"<script>alert('Sila isi nama anda')</script>";  
    exit();  
    }  

    if($jawatan3=='')  
    {  
        echo"<script>alert('Sila nyatakan jawatan anda')</script>";  
    exit();  
    }

    if($tarikh3=='')  
    {  
        echo"<script>alert('Sila nyatakan tarikh anda respon')</script>";  
    exit();  
    }

//insert the user into the database.  
    $admin_query="UPDATE `permohonan` SET `mohon`=:mohon,`nama3`=:nama3,`jawatan3`=:jawatan3,`tarikh3`=:tarikh3 WHERE `view_id`=:view_id"; 
    if(mysqli_query($dbcon,$admin_query)) 
    {  
        echo"<script>window.open('welcomeadmin.php','_self')</script>";  
    }  

}  

?>  

Here is my senaraipemohon.php:

<html> <head lang="en"> <meta charset="UTF-8"> <link type="text/css" rel="stylesheet" href="bootstrap-3.2.0-dist\css\bootstrap.css"> <!--css file link in bootstrap folder--> <title>View Users</title> </head> <style>  
    .login-panel {  
        margin-top: 150px;  
    }  
    .table {  
        margin-top: 50px;  

    }  

</style> <body> <div class="table-scrol"> <h1 align="center">All the Users</h1> <div class="table-responsive"><!--this is used for responsive display in mobile and other devices--> <table class="table table-bordered table-hover table-striped" style="table-layout: fixed"> <thead> <tr> <th>kepada</th> <th>nama</th> <th>jawatan</th> </tr> </thead> <?php  
        include('db_connection.php'); 
        $view_users_query="select * from permohonan";//select query for viewing users.  
        $run=mysqli_query($dbcon,$view_users_query);//here run the sql query.  

        while($row=mysqli_fetch_array($run))//while look to fetch the result and store in a array $row.  
        {  
            $user_id=$row[0];  
            $kepada=$row[1];  
            $nama=$row[2];  
            $jawatan=$row[3];  
            $tarikh1=$row[4];
            $jam1=$row[5];
            $jam2=$row[6];
            $kerana=$row[7];
            $tarikh2=$row[8];
            $nama2=$row[9];
            $jawatan2=$row[10];
            $mohon=$row[11];
            $nama3=$row[12];
            $jawatan3=$row[13];
            $tarikh3=$row[14];

        ?> <tr> <!--here showing results in the table --> <td><?php echo $kepada;  ?></td> <td><?php echo $nama;  ?></td> <td><?php echo $jawatan;  ?></td> <td><a href="lihatpemohon.php?get=<?php echo $user_id ?>"><button class="btn btn-danger">LIHAT</button></a></td> <!--btn btn-danger is a bootstrap button to show danger--> </tr> <?php } ?> </table> </div> </div> </body> </html>

Can someone correct me, i guess my update query is the problem.

Writing code like this is nuts.

Why is everything (logic, presentation) jumbled up in one file? Why is your //insert the user into the database. comment immediately followed by an update statement?

I'm not going to solve your problem (or maybe homework question) for you. But the actual actions should be in a controller and your template should be in a, well, template.

class Blah::Create

  before_filter :check_officer

  def new
    # insert a Blah, I have no idea what a permohonan is
  end

  private

  def check_officer
    # is the current user an officer?
  end

end

class Blah::Modify

  before_filter :check_admin

  def update(id)
    # update Blah with value id
  end

  private

  def check_admin
    # is the current user an admin?
  end

end

you are not binding parameters in the update query.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.