如何将register.php中的echo显示到index.php

时间:2017-04-18 12:42:20

标签: php email

我有index.php和register.php,concent.php文件。当我点击按钮并检查电子邮件是否正确时,我希望index.php显示$ msg(成功/错误)。

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

                   }}?>

2 个答案:

答案 0 :(得分:0)

您应该将$msg放入$_SESSION['msg']并尝试在index.php中访问

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

答案 1 :(得分: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