2017-04-18 26 views
-2

我有index.php和register.php,concent.php文件。我想index.php顯示$味精(成功/錯誤),當我點擊按鈕,並檢查電子郵件是否正確。如何顯示來自register.php的回顯到index.php

的index.php

<?php 
include 'core/int.php'; // $msg = ' '; 
include 'includes/overall/header.php'; // header 
include 'includes/overall/content.php'; // content 
echo $msg;           // HOW TO DISPLAY SUCCESS OR ERROR?? 
include 'includes/overall/footer.php'; ?> 

content.php

<form action="register.php" method="post"> 

<input type="text" name="email" class="input" placeholder="Address email"> &nbsp 
<input type="text" name="email_r" class="input" placeholder="Reply address"> &nbsp <input type="submit" name="register" class="button button-primary" value="REGISTER"> 

<aside class="log_reg3"> 

    <input type="checkbox" name="tems" value="tems"> I Accept TEMS &nbsp 
     <a href="?register">Register</a> &nbsp Forgotten your <a href="recover.php?mode=username">username</a> and <a href="recover.php?mode=password">password</a> 
</aside> 

register.php

<?php include 'core/int.php'; // $db, $msg 

if(!empty($_POST['email']) && isset($_POST['email']) && !empty($_POST['email_r']) && isset($_POST['email_r'])) { 

    $email=($_POST['email']); 
    $email_r=($_POST['email_r']); 

    $regex = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/'; 

    if(preg_match($regex, $email)) { 

       $msg = 'success';   } 

    else { 

     $msg = 'error'; 

        }}?> 
+0

你只是在尋找'$ _SESSION'來在一頁上設置一個值然後在下一個頁面上顯示它? – David

回答

0

你應該把$msg$_SESSION['msg']和T RY在訪問的index.php作爲

if(!empty($_SESSION['msg'])){ 
    echo $_SESSION['msg']; 
    unset($_SESSION['msg']); 
} 
0

的index.php

<?php 
include 'core/int.php'; 
include 'includes/overall/header.php'; 
include 'includes/overall/register.php'; // <---- add this 
include 'includes/overall/content.php'; 
echo $msg;   
include 'includes/overall/footer.php'; ?> 

和content.php變化行動的index.php

<form action="index.php" method="post"> 

<input type="text" name="email" class="input" placeholder="Address email"> &nbsp 
<input type="text" name="email_r" class="input" placeholder="Reply address"> &nbsp <input type="submit" name="register" class="button button-primary" value="REGISTER"> 

<aside class="log_reg3"> 

    <input type="checkbox" name="tems" value="tems"> I Accept TEMS &nbsp 
     <a href="?register">Register</a> &nbsp Forgotten your <a href="recover.php?mode=username">username</a> and <a href="recover.php?mode=password">password</a> 
</aside> 

在register.php刪除include 'core/int.php'; // $db, $msg