如果php变量显示/隐藏它是真的

时间:2017-06-14 08:38:05

标签: php html mysqli

这是我的HTML代码:

<div id="view" class="login-box animated fadeInUp"<?php if ($reg===true){?>style="display:none"<?php } ?>>

        </div>

        <div id="popup"<?php if ($reg===false){?>style="display:none"<?php } ?>>
        </div>

这是我的PHP代码的一部分:

<?php
 ob_start();
 session_start();
error_reporting( ~E_DEPRECATED & ~E_NOTICE );

 $conn = mysqli_connect('localhost','root','','slide-uploader');

 if ( !$conn ) {
  die("Connection failed : " . mysqli_connect_error());
 }

 $error = false;
 $reg = false;

 /*Verifico i campi della form*/
 if ( isset($_POST['submit']) ) {


  $email = trim($_POST['user_email']);
  $email = strip_tags($email);
  $email = htmlspecialchars($email);
  $mailValidation = explode('@',$email)[1];
  $matricola = trim($_POST['user_matricola']);
   $name = ucfirst(explode('.',$email)[0]);
   $surname = ucfirst(preg_replace('/[0-9]+/', '', explode('@',explode('.',$email)[1]))[0]);
   $queryS = "SELECT * FROM studente WHERE Matricola ='$matricola'";
   $resS = mysqli_query($conn,$queryS);
   $count = mysqli_num_rows($resS);
   if($count<1){
     $query = "INSERT INTO studente (Matricola, Nome, Cognome, User) VALUES('$matricola','$name','$surname','$email')";
     $res = mysqli_query($conn,$query);
   }else{
     some code...
   }

   if ($res) {
    some code...
    unset($email);
    $reg = true;
    some code...
   } else {
     some code...
   }
  }
 }
ob_end_flush();
?>

我记录用户,然后返回上一页(window.history.go (-1)),但似乎没有设置$reg

我应该在html页面中设置$ reg变量吗? html页面和php页面是两个单独的文件。

我应该使用变量$ _SESSION吗?

2 个答案:

答案 0 :(得分:0)

我无法完全理解您的网站应该做什么,但如果您只是想隐藏/显示html内容,具体取决于变量是false还是if ( $var ) //$var is true; display content { ?> <div>Your html content that is supposed to be shown</div> <?php } ,你可以用类似的逻辑来做到这一点:

else

如果不是true,您甚至可以添加if ( $var ) //$var is true; display content { ?> <div>Your html content that is supposed to be shown</div> <?php } else { ?> <div>A different html content</div> <?php } 来显示不同的内容。

Office.context.mailbox.item.saveAsync(function(result){..}

答案 1 :(得分:0)

我不知道你为什么用过&#34; display:none&#34;对于真实和虚假的情况。您可以尝试&#34; display:block;&#34; if $ reg为true(在两个地方 style 之前还包括一个空格)

<div id="view" class="login-box animated fadeInUp" <?php if ($reg===true){?> style="display:block;"<?php } ?>>

    </div>

<div id="popup"<?php if ($reg===false){?> style="display:none"<?php } ?>>
    </div>
相关问题