php - 如何在 PHP 中使用 OR 运算符?

标签 php mysql forms operators

我有一个代码,我在其中检查变量值并尝试应用 OR 运算符,但失败了。我的文件有编辑代码。在我的场景中,我使用 4 个提交按钮如保存、提交、批准和重新提交。现在在编辑文件上,我启动一个 session 并应用条件,如果有用户,则显示“保存”和“提交”按钮,但如果有经理,则显示“批准”和“重新提交”按钮。 根据经理条件,我想应用另一个 if 条件,即如果以前的状态是“批准”,则仅显示“重新提交”按钮,如果以前的状态是“保存”或“提交”,则显示“批准”和“重新提交”按钮

下面是我的代码

<?php
include ("session1.php");
?>
<?php
    require 'database.php';
    $id = null;
    if ( !empty($_GET['id'])) {
        $id = $_REQUEST['id'];
    }

    if ( null==$id ) {
        header("Location: index.php");
    }

    //------------------------------------------Update-------------------------------- 
    if ( !empty($_POST)) {
$editor1 =mysql_real_escape_string(trim($_POST['editor1']));
$editor2 =mysql_real_escape_string(trim($_POST['editor2']));
$editor3 =mysql_real_escape_string(trim($_POST['editor3']));
$editor4 =mysql_real_escape_string(trim($_POST['editor4']));
$editor5 =mysql_real_escape_string(trim($_POST['editor5']));
$editor6 =mysql_real_escape_string(trim($_POST['editor6']));
$editor7 =mysql_real_escape_string(trim($_POST['editor7']));
$editor8 =mysql_real_escape_string(trim($_POST['editor8']));
$editor9 =mysql_real_escape_string(trim($_POST['editor9']));
$editor10 =mysql_real_escape_string(trim($_POST['editor10']));
if($_POST['submit'] == "Submit"){
$status=$_POST['submit'];}

if($_POST['submit'] == "Save"){
$status=$_POST['submit'];}


if($_POST['submit'] == "Approve"){
$status=$_POST['submit'];}

if($_POST['submit'] == "Re-Submit"){
$status=$_POST['submit'];}

$valid = true;
        if ($valid) {
            $pdo = Database::connect();
            $sql = "UPDATE test1  set editor1 ='$editor1', editor2 ='$editor2', editor3 ='$editor3',
                                        editor4 ='$editor4', editor5 = '$editor5', editor6 ='$editor6',
                                        editor7 ='$editor7', editor8 ='$editor8', editor9 ='$editor9',
                                        editor10 ='$editor10', status='$status'  WHERE id ='$id'";
            $q = $pdo->prepare($sql);
            $q->execute(array($editor1,$editor12,$editor3,$editor4,$editor5,$editor6,$editor7,$editor8,$editor9,
            $editor10,$status,$id));
            Database::disconnect();
            header("Location: index.php");
        }
}
    else { 
          }

    $con=mysqli_connect("localhost","root","","pacra1");

         $id2 = $_GET['id'];
        $sql = "SELECT * FROM test1 where id='$id2'";

            $result=mysqli_query($con,$sql);

            $row= (mysqli_fetch_array($result,MYSQLI_ASSOC));

$editor1 =($row['editor1']);
$editor2 =($row['editor2']);
$editor3 =($row['editor3']);
$editor4 =($row['editor4']);
$editor5 =($row['editor5']);
$editor6 =($row['editor6']);
$editor7 =($row['editor7']);
$editor8 =($row['editor8']);
$editor9 =($row['editor9']);
$editor10 =($row['editor10']);
$status =($row['status']);

    ?>

<!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>
<link rel="stylesheet" type="text/css" href="newstyles.css">
<link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" /> 
 <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">

<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

<script type="text/javascript" src="../../scripts/jquery-1.11.1.min.js"></script> 
<script type="text/javascript" src="../../scripts/demos.js"></script> 
<script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script> 
<script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script> 
<script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script> 
<script type="text/javascript" src="../../jqwidgets/jqxlistbox.js"></script> 
<script type="text/javascript" src="../../jqwidgets/jqxdropdownlist.js"></script> 
<script type="text/javascript" src="../../jqwidgets/jqxdropdownbutton.js"></script> 
<script type="text/javascript" src="../../jqwidgets/jqxcolorpicker.js"></script> 
<script type="text/javascript" src="../../jqwidgets/jqxwindow.js"></script> 
<script type="text/javascript" src="../../jqwidgets/jqxeditor.js"></script> 
<script type="text/javascript" src="../../jqwidgets/jqxtooltip.js"></script> 
<script type="text/javascript" src="../../jqwidgets/jqxcheckbox.js"></script> 
</head>

<body>
  <script type="text/javascript">
        $(document).ready(function () {
            $('#editor1').jqxEditor({tools: 'bold italic underline | left center right'
            });

            $('#editor2').jqxEditor({tools: 'bold italic underline | left center right'
            });

            $('#editor3').jqxEditor({tools: 'bold italic underline | left center right'
            });

            $('#editor4').jqxEditor({ 
            });

             $('#editor5').jqxEditor({tools: 'bold italic underline | left center right'
            });
            $('#editor6').jqxEditor({ 
            });
            $('#editor7').jqxEditor({tools: 'bold italic underline | left center right'
            });
            $('#editor8').jqxEditor({tools: 'bold italic underline | left center right'
            });
            $('#editor9').jqxEditor({tools: 'bold italic underline | left center right'
            });
            $('#editor10').jqxEditor({tools: 'bold italic underline | left center right'
            });
            $('#editor11').jqxEditor({
            });

        });
    </script>

    <div style="margin-top: 10px; width: 800px">

    <div style=" margin:auto; width:60px; height:auto; align: middle">
    <img src="image/pacra_logo.png" alt="logo">
    </div>
    <div style="margin:auto; width:auto; text-align:center; font-family:'Times New Roman', Times, serif; font-variant: small-caps; font-size:20px; font-weight:bold">
    The Pakistan Credit Rating Agency Limited 
    <hr></div>
    <form action="edit.php?id=<?php echo $id; ?>" method="POST" > 
                <div style="width: 30%; float:left; line-height:0.5" contenteditable="true"><textarea name="editor1" id="editor1"><?php echo(nl2br($editor1));?></textarea>
                </div>
                 <div style="clear: both;"></div>
           <div style=" margin-top:30px; width:35%; float:left; font-family:'Times New Roman', Times, serif; text-align:left; font-size:14px; line-height:0.5" contenteditable="true"><textarea name="editor2" id="editor2"><?php echo(nl2br($editor2));?></textarea></div>
            <div style=" margin-top:30px; margin-left:220px; width:35%; float:left; font-family:'Times New Roman', Times, serif; text-align:right; font-size:14px; line-height:0.5" contenteditable="true"><textarea name="editor3" id="editor3"><?php echo (nl2br($editor3));?></textarea></div>
             <div style="clear: both;"></div>
          <div style="margin-top:40px; margin-right:auto; width:auto; font-family:'Times New Roman', Times, serif; text-align:center; font-variant:small-caps; font-size:18px; font-weight:bold; line-height:0.5" contenteditable="true"><textarea name="editor4" id="editor4"><?php echo(nl2br($editor4));?></textarea></div>
         <div style=" margin-top:20px; width:20%; float:left; font-family:'Times New Roman', Times, serif; text-align:left; font-size:16px; line-height:0.5" contenteditable="true"><textarea name="editor5" id="editor5"> <?php echo(nl2br($editor5));?></textarea></div> 

    <div style="clear: both;"></div>
    <div style="margin-top: 10px; width: 800px; text-align:justify; font-family:'Times New Roman', Times, serif; font-size:14px; line-height:0.5" contenteditable="true"><textarea name="editor6" id="editor6"><?php echo (nl2br($editor6));?></textarea></div>

    <div style="margin-top:30px; width:auto; float:left; text-align:left; font-family:'Times New Roman', Times, serif; font-size:16px" contenteditable="true"><textarea name="editor7" id="editor7"><?php echo(nl2br($editor7));?></textarea></div>
    <div style="clear: both;"></div>
    <div style="margin-top:100px; width:auto; float:left; text-align:left; font-family:'Times New Roman', Times, serif; font-size:16px; font-variant:small-caps" contenteditable="true"><textarea name="editor8" id="editor8"><?php echo (nl2br($editor8));?></textarea></div>
<div style="clear: both;"></div>
    <div style="margin:auto; width:auto; float:left; text-align:left; font-family:'Times New Roman', Times, serif; font-size:16px;" contenteditable="true"><textarea name="editor9" id="editor9"><?php echo(nl2br($editor9));?></textarea></div>    
    <div style="clear: both;"></div>
    <div style="margin-top:40px; width:auto; height:30px float:left; text-align:left; font-family:'Times New Roman', Times, serif; font-size:16px;" contenteditable="true">
    <textarea name="editor10" id="editor10"><?php echo(nl2br($editor10));?></textarea>
    </div>
    <div style="margin-top:100px">
    <?php

 if($_SESSION['UserName']=='User')
{
?>
    <input type="submit" name="submit" value="Save">
    <input type="submit" name="submit" value="Submit">
<?php   

    }
    if($_SESSION['UserName']=='Manager')
{
    $_POST['submit']="";

if($_POST['submit'] == "Save" || "Submit")
    {
?>
    <input type="submit" name="submit" value="Approve">
    <input type="submit" name="submit" value="Re-Submit">

<?php   
    }
    }
    else
    {
?>
<input type="submit" name="submit" value="Re-Submit">
<?php
    }
    ?>


    </div>
    </form>
<div style="clear: both;"></div>
    <div style="margin-top:70px; width:800px; float:left; text-align:center; font-family:'Times New Roman', Times, serif; font-size:18px;">
    <hr>
 <strong>Awami Complex FB-1, Usman Block, New Garden Town, Lahore-54600, Pakistan</strong>  
 </br>PABX: 92(42)35869507 Fax: 92(42)35830425 Email: pacra@pacra.com 
 </br>www.pacra.com
    </div>
    </div>
</body>
</html>

这是我遇到问题的代码

<?php 

if($_SESSION['UserName']=='User')
{
?>
    <input type="submit" name="submit" value="Save">
    <input type="submit" name="submit" value="Submit">
<?php   

    }
    if($_SESSION['UserName']=='Manager')
{
    $_POST['submit']="";

if($_POST['submit'] == "Save" || "Submit")
    {
?>
    <input type="submit" name="submit" value="Approve">
    <input type="submit" name="submit" value="Re-Submit">

<?php   
    }
    }
    else
    {
?>
<input type="submit" name="submit" value="Re-Submit">
<?php
    }
    ?>

最佳答案

您要将此处的 $_POST['submit'] 更改为空白。使用下面的代码。

remove this line $_POST['submit']="";

And change the following to

<?php
if($_SESSION['UserName']=='Manager')
{

    if($status == 'Approve')
    {
?>
    <input type="submit" name="submit" value="Re-Submit">
    

<?php   
    }
    else
    {
?>
    <input type="submit" name="submit" value="Approve">
    <input type="submit" name="submit" value="Re-Submit">
<?php
    }
}
?>

关于php - 如何在 PHP 中使用 OR 运算符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31399441/

相关文章:

Mysql 日期字段索引

mysql - 在存储过程中打印多行

forms - Symfony2 - 如何在使用 query_builder 时自定义实体字段类型的选择选项标签?

php - MYSQL 极限数学

php - ZF2 动态菜单 Zend\Navigation\Navigation

sql - 在 SQL 中选择最大订单号

PHP:如何更改 SQL 中验证的值?

HTML 5 验证错误显示字段的 onblur 而不是 onsubmit

php - 集合的 Laravel 5.5 API 资源(独立数据)

php - 将表格转换为复杂数组php