2017-06-14 10 views
-3

本当場合:表示/非表示PHPの変数は、それがこれは私の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ページは2つの別々のファイルです。

変数$ _SESSIONを使用する必要がありますか?

+0

trueの場合?'あなたは.htmlのファイルを意味するのですか? PHPはhtmlファイルでは実行できません。 – Andreas

+0

@Andreas実際にPHPを.html-filesとして解析するようにサーバを設定することは可能です。しかし、それはお勧めしません。 – StuntHacks

+0

あなたのコードはSQLインジェクションに対して脆弱です。これを修正する必要があります。 – Enstage

答えて

0

あなたのウェブサイトが何をすべきかを完全に理解できませんでしたが、変数がtruefalseかによってHTMLコンテンツを表示/非表示にしたい場合は、この:

if ($var) //$var is true; display content 
{ 
    ?> 
     <div>Your html content that is supposed to be shown</div> 
    <?php 
} 

あなたも、それがtrueでない場合は、別のコンテンツを表示するには、elseを追加することができます。

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 
} 
0

真と偽の両方の状況で "display:none"を使用した理由はわかりません。あなたは "display:block;"あなたは `$のREG変数がhtmlページに言うときの$ REGは(も両方の場所でスタイルの前に空白を含める)

<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> 
関連する問題