PHP로 MySQL 테이블에 데이터를 삽입하려고합니다. 사용자 이름과 비밀번호 같은 양식 데이터를 게시하고 싶은 양식이 있습니다. 모든 것이 잘된 것처럼 보이지만 데이터가 데이터베이스에 게시되지 않습니다. 내 데이터베이스 연결은 여기가 db_connection.php
라는 파일입니다 ... 간단하다내 양식 데이터가 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() . ")"
);
}
?>
의 형식은 페이지가 newUser.php
라고하며 그 자체에 게시합니다. 여기에 페이지가 있습니다 :
<?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"/> 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"/> 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"); ?>
제출 버튼을 클릭하면 양식 필드가 지워지고 아무것도 저장되지 않습니다. 데이터가 게시되지 않은 이유를 결정하는 데 도움을받을 수 있습니까? 감사!
표시 오류가 있습니까? – violator667
'var_dump ($ result)'와 같은 기본적인 디버깅을 수행하여 부울 false인지 확인하십시오. 당신은 단순히 당신의 질문이 항상 성공할 것이라고 가정하고 있습니다. 왜냐하면 BASIC 에러 검사조차도 했었다면, 필드 목록에'hashed_password' 후에 여분의 쉼표로 인한 구문 오류에 대해 들었을 것입니다. –
'hashed_password,'<='$ result = mysqli_query ($ connection, $ query) 또는 die (mysqli_error ($ connection));에 대한 불량 쉼표는 http://php.net과 마찬가지로 /manual/en/function.error-reporting.php –