2014-06-19 2 views
-1

사용자가 양식의 정보를 채우고 제출 버튼을 클릭하면 데이터를 데이터베이스에 저장합니다. 데이터베이스에서 연결 테스트를해도 문제가 없습니다.PDO의 내 삽입 데이터가 작동하지 않습니다

내 문제는 지금 아무도 내가 코드를 잘못 수정하는 데 도움이되지 않을 것입니다?

의 index.php :

<?php include_once('header.php'); ?> 
<html lang="en"> 
<head> 
<script src="bootstrap/js/jquery-1.11.0.min.js"></script> 
<style> 
#Picture { 
    width: 120px; 
    height: 120px; 
} 
#imgInp { display:none;} 
</style> 
<script type="text/javascript"> 
$(document).ready(function() { 
    var currentSrc = $('#Picture').attr('src'); 
    if(currentSrc==null || currentSrc==""){   
    $('#Picture').attr('src','http://i38.photobucket.com/albums/e149/eloginko/profile_male_large_zpseedb2954.jpg'); 

    $("#Picture").on('click', function() { 
     $("#imgInp").trigger('click')} 
    )} 


    function readURL(input) { 
     if (input.files && input.files[0]) { 
      var reader = new FileReader(); 

      reader.onload = function (e) { 
       $('#Picture').attr('src', e.target.result); 
      } 

      reader.readAsDataURL(input.files[0]); 
     } 
    } 

    $("#imgInp").change(function(){ 
     readURL(this); 
    }); 

}); 

</script> 
</head> 
<body> 
<form method="post" action="index.php" enctype="multipart/form-data"> 
<img id="Picture" name="Picture" data-src="#" /> <br /> 
<input type='file' id="imgInp" accept="image/*" /><br /> 
Name: <input type="text" id="name" name="name" /><br /> 
Age: <input type="text" id="age" name="age" /><br /> 
Address: <input type="text" id="address" name="address" /><br /> 
<input type="radio" name="gender" id="gender" value="male" />Male 
<input type="radio" name="gender" id="gender" value="Female" />Female<br /> 
<input type="submit" name="add" value="Add" /> 
</form> 
</body> 
</html> 

header.php :

<?php 
$host = "localhost"; 
$user = "root"; 
$pass = ""; 
$db = "test"; 

$dbc = new PDO("mysql:host=" . $host . ";dbname=" . $db, $user, $pass); 

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

    $name = isset($_POST['name']) ? $_POST['name'] : null; 
    $age = isset($_POST['age']) ? $_POST['age'] : null; 
    $address = isset($_POST['address']) ? $_POST['address'] : null; 
    $gender = isset($_POST['gender']) ? $_POST['gender'] : null; 
    $picture = isset($_FILES['Picture']) ? $_FILES['Picture'] : null; 

    $q = "INSERT INTO students(name, age, address, gender, profile_pic) VALUES(:name, :age, :address, :gender, :Picture)"; 

    $query = $dbc->prepare($q); 
    $query->bindParam(':name', $name); 
    $query->bindParam(':age', $age); 
    $query->bindParam(':address', $address); 
    $query->bindParam(':gender', $gender); 
    $query->bindParam(':Picture', $picture); 

    $results = $query->execute(); 

} 
?> 
+0

어떤 어이 있습니까 브라우저의 콘솔에있는 서버 측 error.log? –

+0

양식은'action = "index.php"'라고하지만 삽입 스크립트는'header.php'입니다. – Barmar

+0

이것은 게시 한 세 번째 시간인데 그 중 2 개가 삭제 되었습니까? 그 이유는 무엇입니까? –

답변

1

변경이 -

<form method="post" action="index.php" enctype="multipart/form-data"> 

이에 -

<form method="post" action="header.php" enctype="multipart/form-data"> 
+1

이것이 OP 문제를 해결할 수 있기를 바랍니다. 그/그녀가 같은 질문을 올린 것은 세 번째입니다. –

+0

header.php는 이미 index.php에 포함되어 있습니다. 이것은 나에게 문제가되지 않는다. –

+1

@ThinkDifferent 그렇다면 다음을 사용하십시오 :'

' – TiMESPLiNTER

관련 문제