2014-12-18 2 views
1

내 양식을 제출하려고 할 때 나는 다음과 같은 오류가 점점 오전 : 나는 같은 오류와 함께 다른 모든 게시물을 검사 한PHP의 mysqli_stmt_execute() 오류

Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in     /Applications/MAMP/htdocs/phpv1/v1/editprofilephp.php on line 66 

Warning: mysqli_stmt_affected_rows() expects parameter 1 to be mysqli_stmt, boolean given in /Applications/MAMP/htdocs/phpv1/v1/editprofilephp.php on line 68 
Error Occurred 

Warning: mysqli_error() expects exactly 1 parameter, 0 given in /Applications/MAMP/htdocs/phpv1/v1/editprofilephp.php on line 83 

Warning: mysqli_stmt_close() expects parameter 1 to be mysqli_stmt, boolean given in /Applications/MAMP/htdocs/phpv1/v1/editprofilephp.php on line 85 

을 내가 실수 중 하나를하지 않았 그 (것)들에서 언급되는.

내 PHP는 : 나는 다른 목적을 위해 웹 사이트의 이전 섹션에서 이전에이 코드를 사용하고 난 아무 문제가 없었어요

<?php 
session_start(); 

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



$data_missing = array();  

if(empty($_POST['aboutme'])){ 

    // Adds name to array 
    $data_missing[] = 'aboutme'; 

} else { 

    // Trim white space from the name and store the name 
    $aboutme = trim($_POST['aboutme']); 

} 

if(empty($_POST['full_name'])){ 

    // Adds name to array 
    $data_missing[] = 'full_name'; 

} else { 

    // Trim white space from the name and store the name 
    $full_name = trim($_POST['full_name']); 

} 

if(empty($_POST['friend'])){ 

    // Adds name to array 
    $data_missing[] = 'friend'; 

} else { 

    // Trim white space from the name and store the name 
    $friend = trim($_POST['friend']); 

} 





    if(empty($data_missing)){ 
    $id = $_SESSION["user_id"];  

    require_once('mysqli_connect.php'); 

    $query = "UPDATE userprofile SET full_name='{$full_name}' aboutme='{$aboutme}' friend='{$friend}' WHERE id='{$id}' LIMIT 1"; 

    $stmt = mysqli_prepare($dbc, $query); 


    //i Interger 
    //d Doubles   
    //s Everything Else 



    mysqli_stmt_execute($stmt); 

    $affected_rows = mysqli_stmt_affected_rows($stmt); 

    if($affected_rows == 1){ 

     echo 'Student Entered'; 



     mysqli_stmt_close($stmt); 

     mysqli_close($dbc); 

    } else { 

     echo 'Error Occurred<br />'; 
     echo mysqli_error(); 

     mysqli_stmt_close($stmt); 

     mysqli_close($dbc); 

    } 

} else { 

    echo 'You need to enter the following data<br />'; 

    foreach($data_missing as $missing){ 

     echo "$missing<br />"; 

    } 

} 

}else { 
echo mysqli_error(); 
}   

?>   

. 나는 오랜 시간 동안 오류를 찾는데 아무런 노력을 기울이지 않았고 성공을 거두지 않았기 때문에 여기서 물어보기로했다.

+2

왜 *없이 문 *을 준비'있다'그것에서의? 사용자가 입력 한 값을 SQL 쿼리에 연결하는 것은 탈출이나 위생 처리가 없으므로 끔찍한 생각입니다. –

답변

2

오류는 SQL의 오류로 인해 발생합니다. 오류로 인해 명령문이 준비되지 않습니다.

질문 :

$query = "UPDATE userprofile SET full_name='{$full_name}' aboutme='{$aboutme}' friend='{$friend}' WHERE id='{$id}' LIMIT 1"; 

당신은 열 사이에 쉼표 놓치고 :

$query = "UPDATE userprofile SET full_name='{$full_name}', aboutme='{$aboutme}', friend='{$friend}' WHERE id='{$id}' LIMIT 1"; 

그리고 그것은 가치가 무엇인지, 제대로 준비된 문을 사용하지 않는 위해, - 당신이있어를 여전히 SQL 인젝션에 취약한 쿼리에 값을 직접 설정합니다. 에

시도 업데이트 :

$query = "UPDATE userprofile SET full_name=?, aboutme=?, friend=? WHERE id=? LIMIT 1"; 
$stmt = mysqli_prepare($dbc, $query); 
if ($stmt) { 
    mysqli_stmt_bind_param($stmt, "sssi", $full_name, $aboutme, $friend, $id); 
    mysqli_stmt_execute($stmt); 
    // the rest of your code 
} 
+0

그러나'?'변수가 없어도 여전히 제대로 작동할까요? – Pacerier