繁体   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