简体   繁体   English

php创建帐户页面而不重定向到index.html

[英]php Create account page with not redirect to index.html

THis website is for a shipping company where users create an accocunt and get a somewhat virtual mailbox in another country. 该网站适用于一家货运公司,用户可以在该公司创建帐户,并在另一个国家/地区获得某种程度的虚拟邮箱。 When the user creates an account his information is supposed to be sent to the database, and he should be redirected to dashboard.html, However when the create account form is filled out and the submit button pressed the user is supposed to be redirected to index.html but the page wont redirect. 当用户创建一个帐户时,应该将他的信息发送到数据库,并且应该将其重定向到dashboard.html。但是,当填写了创建帐户表单并按下提交按钮时,应该将用户重定向到索引.html,但页面不会重定向。 and there are no errors even with php error reporting on please help . 并且即使有php错误报告也没有错误,请帮助。

   <?php
   session_start();

   ini_set('display_errors', 'On');
   error_reporting(E_ALL | E_STRICT);

    error_reporting(E_ALL);
    ini_set('display_errors', 1);


       if(isset($_POST['submit'])){ 

         //check if variables are empty

     if (!empty($firstname) || !empty($lastname) || !empty($email) || 
         !empty($confirmemail) ||
         !empty($password) || !empty($confirmpassword)  || 
         !empty($phonenumber)    || !empty($address)  || !empty($city)  || 
         !empty($parish)  || !empty($trn)  ) 

        {
          $firstname = $_POST['firstname'];
           $lastname = $_POST['lastname'];
           $email= $_POST['email'];
           $confirmemail = $_POST['confirmemail'];
           $password = $_POST['password'];
           $confirmpassword = $_POST['confirmpassword'];
           $phonenumber = $_POST['phonenumber'];
           $address= $_POST['address'];
           $city = $_POST['city'];
           $parish = $_POST['parish'];
           $trn = $_POST['trn'];


       $DB_NAME= "ship2yaad";
       $DB_USER="root";
        $DB_PASSWORD="";
        $DB_HOST= "localhost";

    //create connection

     $conn= new mysqli("$DB_HOST", "$DB_USER", "$DB_PASSWORD","$DB_NAME");


   if (mysqli_connect_error()) {
   die('Connect Error('. mysqli_connect_errno().')'.mysqli_connect_error());
    } 



     $SELECT = "SELECT email From usersdb Where email = ? Limit 1";
     $INSERT = "INSERT Into usersdb (firstname , lastname , email 
       ,confirmemail , password , confirmpassword , phonenumber, address, 
         city, parish ,trn) 
  values(?,?,?,?,?,?,?,?,?,?,?)";
 //Prepare statement
   # code...



    $stmt = $conn->prepare($SELECT);
    $stmt->bind_param("s", $email);
    $stmt->execute();
    $stmt->bind_result($email);
    $stmt->store_result();
   $rnum = $stmt->num_rows;


    if ($rnum==0) {
        $stmt->close();
        $stmt = $conn->prepare($INSERT);

  // prepare and bind
     $stmt->bind_param("ssssssisssi", $firstname, $lastname, $email, 
      $confirmemail, $password, $confirmpassword ,$phonenumber, 
      $address, $city, $parish , $trn); 
     //binds the parameters to the SQL query and tells the database what the 
    parameters are
      $stmt->execute();

    $stmt->close();
    $conn->close();



        header('Location:dashboard.html');
        }



    ?>
     the database credentials are correct im 100% sure of it. PLus im not getting a sql connect error. 

There are a few issues in your codes; 您的代码中有一些问题;

1. Repeat Definitions 1.重复定义

   ini_set('display_errors', 'On');   // useless because its overwritten
   error_reporting(E_ALL | E_STRICT);  //  uselesss again

   ini_set('display_errors', 1);   // repeat
   error_reporting(E_ALL);   // repeat

Don't repeat. 不要重复。 Pick one and stick with it. 选择一个并坚持下去。

2. Improper closing of loops 2.不正确的循环闭合
Lots of closing braces are not present, results in harder debugging. 没有很多右括号,导致调试困难。


3. The ROOT Cause of your problem. 3.问题的根源。 Incorrect usage of code comments. 错误使用代码注释。

//Prepare statement
# code...

Single line comments start with // and, as the name suggests, should end in the same line. 单行注释以//开头,顾名思义,应在同一行结束。
# code in the code (snippet above) slips in a different line. # code中的# code (上面的代码段)滑到另一行。
If you'd rather use multi-line comments, the correct syntax is 如果您希望使用多行注释,则正确的语法是

/* Multi
   Line
   Comment */

this also occurs here ↓ 这也发生在这里↓

//binds the parameters to the SQL query and tells the database what the 
    parameters are

Notice the difference in code's color ↑ 注意代码颜色的差异↑


My advice 我的建议 -
Use an IDE that offers PHP support and syntax highlighting. 使用提供PHP支持和语法突出显示的IDE。
Atom, Visual Studio Code, PhpStorm etc. Atom,Visual Studio Code,PhpStorm等

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM