dongzaobei0942 2013-03-24 16:45
浏览 57
已采纳

注册成功后,将用户重定向到索引页面并显示弹出窗口

    if (isset($_GET['success']) && empty ($_GET['success'])) {
            echo 'Thank you for registering your service with us!';
            } else {

    //if no errors register user
    if (empty($_POST) === false && empty($errors) === true) {

        $daysavailable='';
        foreach ($_POST['DaysAvailable'] as $value)
        {

        $daysavailable .=$value." ";

        }

        //$test = "Monday, Tuesday";
        $register_info= array (
            'MemberID'  => $_POST['MemberID'],
            'OddJobName'    => $_POST['OddJobName'],
            'Description'   => $_POST['Description'],
            'DaysAvailable' => $daysavailable,
            );
        register_job($register_info);
        if(success){
        echo"<script type=\"text/javascript\">".
            "alert('success');".
            "</script>";
        exit ();
    } else if (empty($errors) === false){
        //otherwise output errors
        echo output_errors($errors);
    }
    }

Looking at previous posts I changed my code to add:

  if(success){ //ADDED CODE
            echo"<script type=\"text/javascript\">".
                "alert('success');".
                "</script>";

Full code:

      if (isset($_GET['success']) && empty ($_GET['success'])) {
            echo 'Thank you for registering your service with us!';
            } else {
    //if no errors register user
    if (empty($_POST) === false && empty($errors) === true) {

        $daysavailable='';
        foreach ($_POST['DaysAvailable'] as $value)
        {

        $daysavailable .=$value." ";

        }


        $register_info= array (
            'MemberID'  => $_POST['MemberID'],
            'OddJobName'    => $_POST['OddJobName'],
            'Description'   => $_POST['Description'],
            'DaysAvailable' => $daysavailable,
            );
        register_job($register_info);

        if(success){ //ADDED CODE
        echo"<script type=\"text/javascript\">".
            "alert('success');".
            "</script>";

        exit ();
    } else if (empty($errors) === false){
        //otherwise output errors
        echo output_errors($errors);
    }
    }

Now I get a pop up, but on the same page and 'success' is an undefined consent.

What I want to happen is that when the user registers successfully they are redirected to index.php and when this page opens I need a pop up to display telling the user they have registered successfully.

I'm not great with PHP (thats probably clear from the above) so any help would be appreciated!

  • 写回答

1条回答 默认 最新

  • doutan3040 2013-03-24 16:51
    关注

    In your registration page do

      if ($success) {
        header('Location: index.php?success=true');
      }
    

    In your index.php

     if ($_GET['success']) {
          echo"<script type=\"text/javascript\">".
                "alert('success');".
                "</script>";
      }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗