-3

This is my html code:

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

This is part of my php code:

<?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();
?>

I log the user and then return to the previous page (window.history.go (-1)) but $reg does not seem to be set.

As I should do to set the $reg variable in the html page? The html page and the php page are two separate files.

Should I use variable $ _SESSION?

6
  • When you say $reg variable in the html page? do you mean a .html file? PHP can't run in a html file. Commented Jun 14, 2017 at 8:40
  • @Andreas It is actually possible to configure your server to parse .html-files as PHP. But it's not recommended. Commented Jun 14, 2017 at 8:42
  • Your code is vulnerable to SQL injection, you need to fix this. Commented Jun 14, 2017 at 8:43
  • @StuntHacks That sounds like a very strange idea. Can't really see the point of that. I mean you only have to rename the file from .html to .php Commented Jun 14, 2017 at 8:43
  • 1
    @Andreas I know. And I don't know why one would do that. Just wanted to state, that it's indeed possible. Commented Jun 14, 2017 at 8:44

2 Answers 2

0

I wasn't able to fully understand what your website is supposed to do, but if you just want to hide/show html content depending on whether a variable is true or false, you can do that with a logic similar to this:

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

You can even add an else, to show different content if it is not 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
}
Sign up to request clarification or add additional context in comments.

Comments

0

I don't know why you have used "display:none" for both true and false situations. You can try "display:block;" if $reg is true (also include a blank space before style in both the places)

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.