php - 注册页面 HTML 未将表单数据发送到 php 代码

标签 php html mysql forms registration

我一直在为我的网站制作一个注册页面,并试图找出为什么在我按下注册按钮后此代码似乎总是回显“尚未提交任何内容”。 HTML 表单的编码方式是否存在问题?或者 php 接收它们的方式?

<?php
session_start();

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
if (isset($_POST['uname'])) {

    include_once("dbconnect.php");

    $uname = strip_tags($_POST["uname"]);
    $pwd = strip_tags($_POST["pword"]);
    $pwdtwo = strip_tags($_POST["pwordtwo"]);

    $unamecheck = mysqli_real_escape_string($dbCon, $usname);
    $pwdcheck = mysqli_real_escape_string($dbCon, $paswd);

    $msg = "Something submitted!";

    // Are the username and password legal?
    if($pwd == $pwdcheck && $unamecheck == $uname) {
      // Is the password confirmed?
      if($pwd == $pwdtwo){
          $sql = "SELECT userID, username, password FROM users WHERE username = '$usname' LIMIT 1";
          $query = mysqli_query($dbCon, $sql);
          $row = mysqli_fetch_row($query);
          // Check to make sure that the username doesn't already exist.
          if(is_null($row[1])){
              $uricheck = strrchr($uname, "@");
              $uriedu = "@my.uri.edu";
              // Check that it is a uri email account.
              if($uricheck !== false && strcmp($uricheck, $uriedu) === 0){
                  $sql = "INSERT INTO `campuskey`.`users` (`userID`, `username`, `password`) VALUES (NULL, '$uname', '$pwd')";
                  mysqli_query($dbCon, $sql);
                  // Set session variables
                  $_SESSION['username'] = $usname;
                  $msg = "You have now registered!";
                  // Now direct to users feed
                  header("Location: user.php");
              } else {
                   $msg = "That is not a valid uri email.";
                  }

          } else {
              $msg = "That email is already in use, fuckface!";
              }
          }
          else {
            $msg = "Either you have typing tourettes or your keyboard's fucked up.  Those passwords don't match up";
            }
    } else {
        $msg = "<h2>What the fuck did you type?  That shit ain't legal!</h2>";
        }
} else {
    $msg = "Nothing submitted yet.";
    }

?>

<!DOCTYPE HTML>

<html>
    <head>
        <meta charset="UTF-8">
        <link href="css/reset.css" rel="stylesheet">
        <link href="css/style.css" rel="stylesheet">
        <title>Campus Key, Page</title>
    </head>
        <body>
            <header>
                <a href="index.html"> <img src="logowhite.png" alt="Campus Key" style="width:150px;height:41px"></a>
            </header>

            <nav class="navigation">
                <div class="non_registerd">
                    <h2><a class="button" href="login.php">Already have an account? Login here!</a></h2>
                </div>
            </nav>

            <form>
                <?php
                  echo $msg;
                 ?><br>
                URI Email: <input class="input" id="email" type="text" name="uname" placeholder="your@my.uri.edu" size="30" required><br>
                Password: <input class="input" id="pass" type="text" name="pword" size="30" required><br>
                Confirm Password: <input class="input" type="text" name="pwordtwo" size="30" required><br>
                <input class="button" type="Submit" name="submit" value="Register"><br>
            </form>
        </body>
    <footer>
        <p><FONT color="#ffffff">Campus Key &copy Whatever We Want</color></p>
    </footer>
</html>

最佳答案

您的表单标记不包含任何操作或方法 atrr 您必须首先像这样定义它们:

     <form  method="POST"  action="<?php echo $_SERVER['PHP_SELF'] ?>"> 

关于php - 注册页面 HTML 未将表单数据发送到 php 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26919306/

相关文章:

php - 如何在 xampp 中启用 curl

php - 避免在 WooCommerce 结账时进行计费电话验证

javascript - 有什么办法可以让页面无法刷新吗?

mysql - 如何在MYSQL中优化/一个查询中进行group by的嵌套求和?

php - 从 MySQL 获取数组到 android

php - 如何从 CodeIgniter 中的 URL 中删除段

html - 如何在调整高度时保持 100% 宽度的 CTA 图片不被拉伸(stretch)?

html - 头部部分不能包含任何标签吗?

mysql - 使用MySQL聚合函数进行比较

Android:将字符串转换为 JSONObject 时出错