簡體   English   中英

無法將表單更新到數據庫

[英]Cannot update the form to the database

hod_view.php ## // 從數據庫申請表單的視圖

<?php
$sql= "SELECT * FROM form WHERE id='$formID'";
$result = mysql_query($sql) or die('Cannot get ID. ' . mysql_error()); 
$row=mysql_fetch_array($result);

$staffID=$row['staff_id'];
$sql2= "SELECT * FROM users WHERE staff_id='$staffID'";
$result2 = mysql_query($sql2); 
$row2=mysql_fetch_array($result2);
?>

<form action="viewProcess.php?action=modifyView&id=<?php echo $row['id']?>" method="post" enctype="multipart/form-data" >
<h3 class="underlineLongest">USER APPLICATION FORM </h3>
<p align="right">Reference Number : <b> <?php echo $row['ref_no']; ?> </b> </p>
<table width='100%'>
    <tr> 
        <td  colspan='2' bgcolor="#C7C7C7"> Applicant Details</td>
    </tr>
    <tr> 
        <td width='30%'>Date of Application </td>
        <td width='70%'> <textColor> <?php echo $row['app_date']; ?> </textColor> </td>
    </tr>
    <tr> 
        <td width='30%'>User Full Name </td>
        <td width='70%'> <textColor> <?php echo $row2['name']; ?> </textColor> </td>
    </tr>
    <tr> 
        <td width='30%'>Designation/Staff ID </td>
        <td width='70%'> <textColor> <?php echo $staffID; ?> </textColor> </td>
    </tr>
    <tr> 
        <td width='30%'>Department/Division </td>
        <td width='70%'> <textColor> <?php echo $row2['department'].'/'.$row2['division']; ?> </textColor> </td>
    </tr>
    <tr> 
        <td width='30%'>Telephone Ext. No </td>
        <td width='70%'> <textColor> <?php echo $row2['ext']; ?> </textColor> </td>
    </tr>
<tr> 
    <td  colspan='2' bgcolor="#C7C7C7" > Application Service Required </td>
</tr>
    <tr> 
    <td width='30%'>Type of Application </td>
    <?php
    $type= $row['type'];
    $result4 = mysql_query(" SELECT * FROM type WHERE type_code='$type'"); 
    $row4=mysql_fetch_array($result4); ?>
    <td width='70%'> <textColor> <?php echo $type.' - '.$row4['description']; ?> </textColor> </td>
</tr>
<tr> 
    <td width='30%'> Type of Facility </td>
    <td width='70%'>
        <textColor> <?php
         $facility=explode(';',$row['facility']);

              foreach($facility as $i =>$key) 
              {
                echo $key .' - ';
                    $result5 = mysql_query(" SELECT * FROM facility WHERE fac_code='$key'"); 
                    while($row5=mysql_fetch_array($result5))   
                    {
                        echo $row5['description'].' <br> ';
                    }
              } ?>
        </textColor> </td>
</tr>

<tr> 
    <td  colspan='2' bgcolor="#C7C7C7" > Endorsed Status (Head of Department) </td>
</tr>
<tr> 
    <td width='30%'>Endorsed By </td>
    <td width='70%'> <textColor> <?php echo $row['endorsed_by']; ?> </textColor> </td>
</tr>
<tr> 
    <td width='30%'>Status </td>
    <td class="alt3">
        <input name="radiobutton1" type="radio" value="APPROVED" checked >Approve
        <input name="radiobutton2" type="radio" value="REJECTED" >Reject
    </td>
</tr>
</tr>
<tr> 
    <td width='30%'>Date & Time </td>
    <td width='70%'> <textColor> <?php echo $row['endorsed_time']; ?> </textColor> </td>
</tr>
<tr> 
    <td width='30%'>Remarks </td>
    <!--<td width='70%'><textarea name="endorsed_remark" id = "endorsed_remark"></textarea> </td> -->
    <td><input type="text" name="endorsed_remark" id="endorsed_remark" /></td>      
</tr>

</table>

<br><br>
<center><p><input class="btnSuccess" type ="submit" name="submit" value="Submit" onclick="modifyView();" >  
   &nbsp;&nbsp;<input class="btnEdit" type="button" name="btnCancel"  value="Cancel" onclick="goBack()" > </p>

這個 hod_view.php 是用戶已經應用的視圖表單。 然后,批准者需要通過將認可的狀態和認可的_remark 更新到數據庫中來批准此表單。

不幸的是,該表單未在數據庫中更新。


viewProcess.php ## // 對數據庫的更新查詢

<?php 
include 'includes/initial.php';
$action = isset($_GET['action']) ? $_GET['action'] : '';

switch ($action)
{
    case 'modifyView' :
        break;

    default :
        header('Location: index.php');
}

function modifyView()
{
    if(isset($_GET['id']) && $_GET['id'] > 0)
    {
        $formID = $_GET['id'];
    }
    else
    { // redirect to index.php if id is not present
        header('Location: index.php');
    }

    echo $formID;

    $sql = "UPDATE form SET endorsed_status='{$_POST['radiobutton1']}',endorsed_remark='{$_POST['endorsed_remark']}' WHERE id='$id'";

    $result = mysql_query($sql) or die('Cannot update. ' . mysql_error());

    if ($_POST['radiobutton2']=='REJECTED')
    {


        $sql = "UPDATE form SET endorsed_status='{$_POST['radiobutton2']}',endorsed_remark='{$_POST['endorsed_remark']}' WHERE id={$id} ";

        $result = mysql_query($sql) or die('Cannot update. ' . mysql_error());

    }
}

**這個viewProcess.php是sql查詢(更新)。 你們能幫我使這個編碼正確嗎?

嘗試這個。

<?php 
include 'includes/initial.php';
$action = isset($_POST['action']) ? $_POST['action'] : '';
 switch ($action)
 {
case 'modifyView' :
    break;

default :
    header('Location: index.php');
 }


 function modifyView()
 {
if(isset($_POST['id']) && $_POST['id'] > 0)
{
    $formID = $_POST['id'];
}
else
{ // redirect to index.php if id is not present
    header('Location: index.php');
}

echo $formID;

$sql = "UPDATE form SET endorsed_status='{$_POST['radiobutton1']}',endorsed_remark='{$_POST['endorsed_remark']}' WHERE id='$id'";

$result = mysql_query($sql) or die('Cannot update. ' . mysql_error());

if ($_POST['radiobutton2']=='REJECTED')
{


    $sql = "UPDATE form SET endorsed_status='{$_POST['radiobutton2']}',endorsed_remark='{$_POST['endorsed_remark']}' WHERE id={$id} ";

    $result = mysql_query($sql) or die('Cannot update. ' . mysql_error());

}
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM