用php写入div

时间:2013-12-16 13:36:41

标签: php html login

这总是显示没有,因为$ msg没有得到回应,当我使用会话解决问题时,总是花了2次错误的尝试告诉我我输入的内容是错误的。所以我尝试了这个,它仍然无法正常工作。我想知道使用php写入div的正确方法;我减少了部分代码,我认为这与代码无关。如果我有任何其他错误,请指出。

<?php 

if (!isset($msg)) $msg = "";
if ($_SERVER['REQUEST_METHOD'] == "POST")
    if ($_POST['formname'] == "Signup Form")
        SignUp();
    else if ($_POST['formname'] == "Signin Form")
        SignIn();

function SignIn()
{
    include 'CONNECT_DB.php';
    $pass = md5();

    $SQLSTATEMENT = ;
    $AMOUNT = mysqli_query($con, $SQLSTATEMENT);
    if ($DATA = mysqli_fetch_array($AMOUNT))
    {
        if($DATA['ACTIVE'] == 1)
        {
            session_destroy();
            session_start();
            $_SESSION['USER_State'] = true;
            $_SESSION['USER_ID'] = $DATA['USER_ID'];
            $_SESSION['time'] = time();
            header('Location: index.php');
        }
        else
        {
            if(!isset($_SESSION)) session_start();
            $_SESSION['USER_ID']=$DATA['USER_ID'];
            $_SESSION['time'] = time();
            header ("Location: Reactivate.php");
        }
    }
    else 
    {
        $msg = "your email is not submitted or your password is invalid";
    }
}

/// ... some validation 

echo "<form name='Signin Form' method='POST' action='" . htmlspecialchars($_SERVER['PHP_SELF']) . "'>
          <input type='hidden' name='formname' value='Signin Form'>
              <table cellspacing='0'>
                  <tr>
                      <td width='25%'></td>
                      <td>
                          <table width='100%'>
                              <tr>
                                  <td><p class='formP'>Email:</p></td>
                                  <td><input class='inputBarLogIn' type='text' name='Email' autofocus>
                              </tr>
                              <tr>
                                  <td><p class='formP'>Password:</p></td>
                                  <td><input class='inputBarLogIn' type='password' name='Password' autofocus>
                                      <div class='divAttention' id='PasswordLogInDiv'>
                                      </div>";
echo $msg;
?>

1 个答案:

答案 0 :(得分:1)

以下可能会更好,并且将来更容易编辑。

[...]
/// ... some validation 
?>

<form name='Signin Form' method='POST' action='<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>'>
<input type='hidden' name='formname' value='Signin Form'>
<table cellspacing='0'>
    <tr>
        <td width='25%'></td>
        <td>
            <table width='100%'>
            <tr>
                <td><p class='formP'>Email:</p></td>
                                    <td><input class='inputBarLogIn' type='text' name='Email' autofocus></td>
            </tr>
            <tr>
                <td><p class='formP'>Password:</p></td>
                                    <td><input class='inputBarLogIn' type='password' name='Password' autofocus> 
                                        <div class='divAttention' id='PasswordLogInDiv' ><?php echo $msg; ?></div>
                                    </td>

您可以像这样在HMTL和PHP之间跳转:

<?php
    if( something == something ) {
?>
        <p>Something is something</p>
<?php
    } else {
?>
        <p>Something is not something</p>
<?php
    }
?>

如果将PHP逻辑与HMTL分开,这可能会使您更容易编写页面,并且可以避免全部回复。