2015-01-08 2 views
-1

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"/>&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"); ?> 

제출 버튼을 클릭하면 양식 필드가 지워지고 아무것도 저장되지 않습니다. 데이터가 게시되지 않은 이유를 결정하는 데 도움을받을 수 있습니까? 감사!

+0

표시 오류가 있습니까? – violator667

+1

'var_dump ($ result)'와 같은 기본적인 디버깅을 수행하여 부울 false인지 확인하십시오. 당신은 단순히 당신의 질문이 항상 성공할 것이라고 가정하고 있습니다. 왜냐하면 BASIC 에러 검사조차도 했었다면, 필드 목록에'hashed_password' 후에 여분의 쉼표로 인한 구문 오류에 대해 들었을 것입니다. –

+0

'hashed_password,'<='$ result = mysqli_query ($ connection, $ query) 또는 die (mysqli_error ($ connection));에 대한 불량 쉼표는 http://php.net과 마찬가지로 /manual/en/function.error-reporting.php –

답변

3

시도 변경

<input type="username" name ="username" value=""/> 변화 여기

<form action="newUser.php" method ="post">newUser.phptype="text"

그것이 무엇을 어디입니까있다?

+0

** 왜''enctype = "multipart/form-data"'를 추가합니까? OP는 아무것도 업로드하거나 첨부하지 않습니다. 그것은 불필요한 것입니다. –

+1

[받아 들인 대답] (http://stackoverflow.com/a/4526286/)을 보시면 다음과 같이 인용하겠습니다 : * "클라이언트 측 코드를 작성할 때 알아야 할 것은'multipart/form- 데이터'** 양식에 ** 모든 '요소가 포함되어있을 때. ** - OP에는 ** 입력 파일이 없습니다. ** 따라서 답변에서 제외하십시오. 목적이 있으며 오해의 소지가 있습니다. –

+0

@ Fred-ii- 감사합니다. 자신감이 조금 넘습니다 –

관련 문제