插入到db后,页面重定向回登录页面

时间:2014-07-03 16:46:19

标签: php forms session login

我的网站有一个简单的登录,当你转到adminSLP页面时,如果用户没有登录,它会重定向到管理员登录页面。问题是当你登录到页面并试着说插入一个记录时我在下面发布的表单将您重定向回登录页面。我不知道我哪里出错了。

ADMIN SLP

 session_start();
// Call this function so your page
// can access session variables

if ($_SESSION['adminloggedin'] != 1) {
    // If the 'loggedin' session variable
    // is not equal to 1, then you must
    // not let the user see the page.
    // So, we'll redirect them to the
    // login page (login.php).

    header("Location: adminLogin.php");
    exit;
    }

ADMIN LOGIN

session_start();
if ($_GET['login']) {
     // Only load the



code below if the GET
 // variable 'login' is set. You will
 // set this when you submit the form

 if ($_POST['adminusername'] == '******'
     && $_POST['adminpassword'] == '*******') {
     // Load code below if both username
     // and password submitted are correct

     $_SESSION['adminloggedin'] = 1;
      // Set session variable

     header("Location: adminSLP.php");
     exit;
     // Redirect to a protected page

 } else echo '<style>#falseLogin{display: block!important;}</style>';
 // Otherwise, echo the error message


}

登录表格

<form method="POST" action="adminLogin.php?login=true" id="adminlogin" style="padding:0">
                    <label for="adminusername">Username:</label>
                    <input type="text" name="adminusername" autocomplete="off"><br/>
                    <label for="adminpassword">Password:</label>
                    <input type="password" name="adminpassword" autocomplete="off" /><br/>
                    <input type="submit" value="Login">
                </form>

用于将记录插入数据库的表格

<form id="trainingForm" method="post" action="" style="display:block;">
                            <div>
                            <h2 id="title" style="color:#c89d64;font-size:36px;font-family: 'RokkittRegular';   margin:0 0 15px; padding:30px 0 30px 0;font-weight:normal;">Add New SLP</h2>

                                    <label for="first_name">First Name</label><input id="first_name" name="first_name" data-required="false" data-validation="length" data-validation-length="min4" type="text">




                                    <label for="last_name">Last Name</label><input id="last_name" name="last_name" data-required="false" data-validation="length" data-validation-length="min4" type="text">
                                    <label for="title">Title</label><input id="title" name="title" data-required="false" data-validation="length" data-validation-length="min4" type="text">




                                    <label for="user_phone">Phone*</label><input id="user_phone" name="user_phone" type="tel" value="(123) 456-7890" data-required="true" onFocus="if(this.value == '(123) 456-7890') this.value='';">


                                    <label for="user_email">Email*</label><input id="user_email" name="user_email" type="email" value="name@something.com" data-required="true" data-validation="email" onFocus="if(this.value == 'name@something.com') this.value='';">





                                <label for="state_name">License Held In:</label><select name='state_name[]' id="state_name" multiple>
                                    <?php 
                                        $result = mysqli_query($con,'SELECT * FROM license_state');

                                        $count = 1;
                                        while($row = mysqli_fetch_array($result))
                                        {
                                            echo '<option value=' . $row['state_name'] . '>' . $row['state_name'] . '</option>';

                                        }
                                    ?>
                                    </select>

                            <span><label for="isChecked">May we post your information on our site?:</label>
                                        <input type="radio" name="isChecked" value="1" checked="checked"><p>Yes</p>
                                        <input type="radio" name="isChecked" value="0"><p>No</p></span>





                                    <label for="asha_number">Asha# (Will Not Be Published)*</label><input id="asha_number" name="asha_number" data-required="true" data-validation="length" data-validation-length="min4" type="text">


                                    <label for="practice_name">Practice Name*</label><input id="practice_name" name="practice_name" data-required="true" data-validation="length" data-validation-length="min4" type="text">





                                    <label for="practice_location">Practice Location*</label><input id="practice_location" name="practice_location" data-required="true" data-validation="length" data-validation-length="min4" type="text">
                                    <span><label for="telepracticeProvider">Are you a telepractice provider?:</label>
                                        <input type="radio" name="telepracticeProvider" id="yes" value="Yes" ><p>Yes</p>
                                        <input type="radio" name="telepracticeProvider" id="no" value="No" checked="checked"><p>No</p></span><br/>


                            <input type="hidden" id='user_id' name='user_id'/>

                                    <br/><button name="submit" id="submit" type="submit">Submit</button>

                            </div>
                        </form>

插入db

if(isset($_POST['submit']))
        {// Create connection
        $con=mysqli_connect("Speechvive.db.11357591.hostedresource.com","****","*****!","Speechvive");


        // Check connection
        if (mysqli_connect_errno()) {
            echo "Failed to connect to MySQL: " . mysqli_connect_error();
        }

        $first_name = $_POST['first_name'];
        $last_name = $_POST['last_name'];
        $title = $_POST['title'];
        $state_name = $_POST['state_name'];
        $asha_number = $_POST['asha_number'];
        $practice_name = $_POST['practice_name'];
        $practice_location = $_POST['practice_location'];
        $user_phone = $_POST['user_phone'];
        $user_email = $_POST['user_email'];
        $isChecked = $_POST['isChecked'];

        $telepracticeProvider = $_POST['telepracticeProvider'];
        $implodeStates = implode(', ',$state_name);

        $insert = "INSERT INTO users ".
               "(first_name,last_name, title, state_name, asha_number, practice_name, practice_location, user_phone, user_email, isChecked, telepracticeProvider) ".
               "VALUES('$first_name','$last_name', '$title', '$implodeStates', $asha_number, '$practice_name', '$practice_location', '$user_phone', '$user_email', '$isChecked', '$telepracticeProvider')";


               $insertData = mysqli_query( $con,$insert  );
        if(! $insertData )
        {
          die('Could not enter data: ' . mysql_error());  
        }
        mysqli_close($con);?>
            <script>window.location = "http://www.speechvive.com/adminSLP.php";//RELOAD THE CURRENT PAGE</script><?php

                    } else if(isset($_POST['save'])){
            // Create connection
            $con=mysqli_connect("Speechvive.db.11357591.hostedresource.com","Speechvive","Slp2014!","Speechvive");


            // Check connection
            if (mysqli_connect_errno()) {
                echo "Failed to connect to MySQL: " . mysqli_connect_error();
            }

            $user_id = $_POST['user_id'];
            $first_name = $_POST['first_name'];
            $last_name = $_POST['last_name'];
            $title = $_POST['title'];
            $state_name = $_POST['state_name'];
            $asha_number = $_POST['asha_number'];
            $practice_name = $_POST['practice_name'];
            $practice_location = $_POST['practice_location'];
            $user_phone = $_POST['user_phone'];
            $user_email = $_POST['user_email'];
            $isChecked = $_POST['isChecked'];

            $telepracticeProvider = $_POST['telepracticeProvider'];
            $implodeStates = implode(', ',$state_name);

            $update = ("UPDATE users SET first_name='$first_name',last_name='$last_name', title='$title', state_name='$implodeStates', asha_number='$asha_number', practice_name='$practice_name', practice_location='$practice_location', user_phone='$user_phone', user_email='$user_email', isChecked='$isChecked', telepracticeProvider='$telepracticeProvider'  WHERE user_id = $user_id");




                   $updateData = mysqli_query( $con,$update  );
            if(! $updateData )
            {
              die('Could not enter data: ' . mysqli_error($con));  
            }
            mysqli_close($con);?>
        <script>window.location = "http://www.speechvive.com/adminSLP.php";</script><?php



        }

1 个答案:

答案 0 :(得分:0)

window.location =“http://www.speechvive.com/adminSLP.php”;

为什么你在插入到db部分中写了这个..我认为这是在创建问题