2013-09-07 3 views
-1

MySQL 데이터베이스에 양식 값 제출. I 오류 메시지가 얻을 그러나 : 행에 문자열 변환문자열 변환에 대한 배열

배열을 45

내가 가진 유일한 배열은 빈 필드를 잡는 $error 배열입니다. 이 같은 HTML 양식이있을 때

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

    $errors = array(); // Initialize erroy array. 

    // Check for title. 
    if (empty($_POST['movie_name'])){ 
     $errors[] = "You forgot to enter a title."; 
    } else { 
     $mn = (trim($_POST['movie_name'])); 
    } 

    if (empty($_POST['leading_actor'])){ 
     $errors[] = "You forgot to enter the leading actor."; 
    } else { 
     $la = (trim($_POST['leading_actor'])); 
    } 

    if (empty($_POST['rating'])){ 
     $errors[] = "Please select a rating."; 
    } else { 
     $rating = ($_POST['rating']); 
    } 

    if (empty($_POST['review'])){ 
     $errors[] = "Please write a review"; 
    } else { 
     $review = (trim($_POST['review'])); 
    } 


    if (empty($errors)) { // If no errors were found. 

     //require_once('./includes/Mysql_connect.php'); 

     // Make the insert query. 

     $query = "INSERT INTO film (movie_title, actor, fk_movie_ratings) 
    **This is line 45** Values ('$mn', '$la', '$rating')"; 

     $result = mysql_query($query); 


     //Report errors. 
    } else { 
     foreach ($errors as $msg){ 
      echo " - $msg <br/> "; 
     } 
    } 
} 
+0

이 알림은 배열을 문자열로 처리 할 때 나타납니다. 45 행에있는 내용을 표시 할 수 있습니까? –

+0

오류가 아니라 경고입니다. –

답변

1

나는 이것이 가능하다고 생각하는 유일한 방법은 다음과 같습니다 때문에의

<input type="text" name="rating[]"> 

을 "[]"PHP는 저장 될 배열을 만들 것 $ _POST [ '등급']. 하지만 내가하는 일이 아닌 것 같습니다.

그런데 POST/GET 입력을 MySQL 쿼리에 직접적으로 넣지 마십시오. 그렇지 않으면 SQL 인젝션을 위험에 빠뜨리기 때문에 대신 준비된 문을 사용하십시오.

관련 문제