我需要一个注册按钮,它将数据发送到mySQL服务器,以便在点击时重定向

时间:2013-12-06 05:02:45

标签: javascript php jquery html mysql

所以我在我的网站上做了一个注册页面。目前它只是一个测试,然后是任何东西。我或多或少地工作,当用户尝试注册时,工作正常,但页面上没有任何变化。我已经创建了一个确认页面,但无论我尝试什么,我似乎无法获得重定向按钮。

    <form name="register" method="post" action="register.php">
        Username:<input name="user" type="text" id="user">
        <br>
        Password:<input name="pass" type="password" id="pass">
        <br>
        Repeat Password:<input name="rpass" type="password" id="rpass">
        <br>
        <input type="submit" name="submit" value="Register">
    </form> 

从我在研究的最后几个小时可以看出,在链接中点击和包装按钮的原因不起作用是因为type =“submit”而不是“button”。有没有办法让这个按钮重定向?如果没有使用HTML或者使用JS或PHP?

    <?php

session_start();  //Must Start a session.

require "config.php"; //Connection Script, include in every file!

//Check to see if the user is logged in.
//'isset' check to see if a variables has been 'set'
if(isset($_SESSION['username'])){
   header("location: members.php");
}

//Check to see if the user click the button
if(isset($_POST['submit']))
{
   //Variables from the table
   $user  = $_POST['user'];
   $pass  = $_POST['pass'];
   $rpass = $_POST['rpass'];

   //Prevent MySQL Injections
   $user  = stripslashes($user);
   $pass  = stripslashes($pass);
   $rpass = stripslashes($rpass);

   $user  = mysqli_real_escape_string($con, $user);
   $pass  = mysqli_real_escape_string($con, $pass);
   $rpass = mysqli_real_escape_string($con, $rpass);

   //Check to see if the user left any space empty!
   if($user == "" || $pass == "" || $rpass == "")
   {
      echo "Please fill in all the information!";
   }

   else
   {
      //Check too see if the user's Passwords Matches!
      if($pass != $rpass)
      {
         echo "Passwords do not match! Try Again";
      }

      //CHECK TO SEE IF THE USERNAME IS TAKEN, IF NOT THEN ADD USERNAME AND PASSWORD INTO THE DB
      else
      {
         //Query the DB
         $query = mysqli_query($con,"SELECT * FROM members WHERE username = '$user'") or die("Can not query the TABLE!");

         //Count the number of rows. If a row exist, then the username exist!
         $row = mysqli_num_rows($query);
         if($row == 1)
         {
            echo "Sorry, but the username is already taken! Try again.";
         }

         //ADD THE USERNAME TO THE DB
         else
         {
            $add = mysqli_query($con,"INSERT INTO members (id, username, password) VALUES (null, '$user' , '$pass') ") or die("Can't                Insert! ");
         }


      }      

   }

}
?>

1 个答案:

答案 0 :(得分:0)

正如我评论的那样,只需做

     else
     {
        $add = mysqli_query($con,"INSERT INTO members (id, username, password) VALUES (null, '$user' , '$pass') ") or die("Can't Insert! ");
        header("location: thankyou.html"); 

     }