Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么我的表单数据没有用php发布到数据库_Php_Html_Forms_Mysqli - Fatal编程技术网

为什么我的表单数据没有用php发布到数据库

为什么我的表单数据没有用php发布到数据库,php,html,forms,mysqli,Php,Html,Forms,Mysqli,我正在尝试使用PHP将数据插入MySQL表。我有一个表单,我想发布表单数据,如用户名和密码。一切似乎都很顺利,但数据并没有发布到数据库中。我的数据库连接很简单。。。这里它来自一个名为db\u connection.php的文件: <?php define("DB_SERVER", "localhost"); define("DB_USER", ""); define("DB_PASS", ""); define("DB_NAME", "global_gl"); //

我正在尝试使用PHP将数据插入MySQL表。我有一个表单,我想发布表单数据,如用户名和密码。一切似乎都很顺利,但数据并没有发布到数据库中。我的数据库连接很简单。。。这里它来自一个名为
db\u connection.php的文件:

<?php
  define("DB_SERVER", "localhost");
  define("DB_USER", "");
  define("DB_PASS", "");
  define("DB_NAME", "global_gl");

  // 1. Create a database connection
  $connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
  // Test if connection succeeded
  if(mysqli_connect_errno()) {
    die("Database connection failed: " . 
      mysqli_connect_error() . 
      " (" . mysqli_connect_errno() . ")"
    );
  }
?>

当我单击submit按钮时,表单字段被清除,没有任何内容保存到数据库中。你能帮我确定为什么不发布数据吗?谢谢

尝试更改

更改
type=“text”

这里


newUser.php
它在哪里它做什么???

完成了任何基本调试,如
var\u dump($result)
以查看它是否为布尔值false?您只是假设您的查询将始终成功。因为如果你做了基本的错误检查,你就会被告知在你的字段列表中的hash_password
之后额外的逗号会导致语法错误。一件事是hash_password,为什么要添加
enctype=“multipart/form data”
?OP没有上传或附加任何东西。这是多余的。请看,我引用:“当您编写客户端代码时,您需要知道的只是当您的表单包含任何
元素时使用
多部分/表单数据。”-OP没有任何输入文件。所以,请从你的答案中删除它,它没有任何意义,而且是误导性的。@Fred ii-谢谢你,对这一点过于自信了,Sanoj。然而,看看,这是另一个问题,你可以看看。它不应该在那里;-)@弗雷德二世-没错
<?php 
    require_once("/includes/session.php");
    require_once("includes/db_connection.php");
    require_once("includes/functions.php");
    require_once("includes/validation_functions.php");
?>

<?php
  if (isset($_POST['submit'])) {
    // Process the form

    // validations
    $required_fields = array("firstName", "lastName", "email", "username",  "password");//TODO:  add country and birthday to this after debugging
    validate_presences($required_fields);

    $fields_with_max_lengths = array("username" => 30);
    validate_max_lengths($fields_with_max_lengths);

    if (empty($errors)) {
      // Perform Create
      $firstName = mysql_prep($_POST["firstName"]);
      $lastName = mysql_prep($_POST["lastName"]);
      $email = mysql_prep($_POST["email"]);
      $username = mysql_prep($_POST["username"]);
      $hashed_password = mysql_prep($_POST["password"]);

      $query  = "INSERT INTO useradmin (";
      $query .= "  firstName, lastName, email, username, hashed_password, ";
      $query .= ") VALUES (";
      $query .= "  '{$firstName}','{$lastName}','{$email}','{$username}','{$hashed_password}'";
      $query .= ")";

      $result = mysqli_query($connection, $query);

      if ($result) {
        // Success
        $_SESSION["message"] = "User created.";
        redirect_to("manage_admin.php");//TODO:  After cretion choose a page to return to.
      } else {
        // Failure
        $_SESSION["message"] = "User creation failed.";
      }
    }
  } else {
    // This is probably a GET request

  } // end: if (isset($_POST['submit']))

?>

<?php include("includes/layouts/header.php"); ?>

<head>

 <script type="text/javascript"    src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js"></script>
 <script type="text/javascript" src="scripts/bday-picker.js"></script>
 <script type="text/javascript">
  $(document).ready(function(){
    $("#createUserDatePicker").birthdaypicker({});

  });
 </script>

</head>
 <div id="main">
  <div id="navigation">
<?php// echo navigation($current_subject, $current_page); ?>
  </div>
  <div id="page">
   <form action="newUser.php" method ="post">  
    <p>First Name:
     <input type = "text" name ="firstName" value=""/>
    </p>
    <p>Last Name:
     <input type = "text" name ="lastName" value=""/>
    </p>
    <p>Email:
     <input type = "email" name ="email" value=""/>
    </p>
    <p>Username:
     <input type = "username" name ="username" value=""/>
    </p>
    <p>Password:
     <input type = "password" name ="password" value=""/>
    </p>
    Counntry:
<?php

  include("countrySelect/index.html");

?><br>

    </p>
    <p>Birthday:

     <div class="picker" id="createUserDatePicker"></div>

    </p>

    <p>
     <input type = "radio" name ="contactMe" value="0"/>&nbsp;  Contact me with news and exclusive conent about Global Gaming League and West Coast Chill products.
    </p>

    <p>
     <input type = "checkbox" name ="accept" value="0"/> &nbsp;I accept the terms of service and privacy policy.
    </p>
    <p>
     <input type="submit" name="submit" value="Create User" />
    </p>
   </form>

   <p>
    <a href ="createUser.php">Cancel</a> <!--Note: this should take us back to a previous page
   </p>

  </div>
 </div>

 <?php include("includes/layouts/footer.php"); ?>