2012-10-23 9 views
0

나는이 문제에 다른 솔루션구문 분석 오류 : 구문 오류, 라인 6

Parse error: syntax error, unexpected T_STRING in /newref-exec.php on line 6 

내가 읽고 부하가 계속하지만 비는

<?php 
// connect to database 
require($DOCUMENT_ROOT . "connect.php"); 
// check for blank entries 
if ($_POST[doi2] == "NULL"){ 
    echo "No Data to add"; 
    } 
    else 
    { 
    $sql="INSERT INTO ref (uid, date, doi, title, year, journal) 
    VALUES 
    ('1','CURDATE()','$_POST[doi2]','$_POST[title2]','$_POST[year2]','$_POST[journal2]')"; 
    if (!mysqli_query($link,$sql,$con)) 
     { 
     die('The Reference could not be added, beacuse of SQL Error:' . mysql_error()); 
     } 
     echo "New Reference Added"; 
    } 
?> 
+1

($ _POST [ 'doi2'] == "NULL") { – koosa

+0

$ DOCUMENT_ROOT', 나는 희망이 * 뜻 *'무엇'$ _SERVER [ 'DOCUMENT_ROOT']'('register_globals'이해야하는 경우 결코있을 수 없다). –

답변

2

이 줄 제대로 작동에 예상치 못한 T_STRING, 주요 요구 사항은 empty 항목을 확인하려는 경우, 당신은 proba 필요, 또한,

if ($_POST['doi2'] == "NULL"){ 

을 따옴표를합니다 bly do this,

if ($_POST['doi2'] == ""){ //checking "NULL", checks for a string 'NULL' 
+0

일반적으로 경고가 아닌 구문 분석 오류가 아닙니까? –

+0

* 필요하지 않습니다. *해야합니다. 이렇게하면 오류가 아닌 경고가 표시됩니다. –

+0

따옴표가 필요한 곳이 많이 있습니다. 그리고 null과 비교할 때 따옴표는 필요하지 않습니다. –

0

다음과 같이 코드를 다시 작성하십시오.

<?php 
// connect to database 
require($DOCUMENT_ROOT . "connect.php"); 
// check for blank entries 
if ($_POST['doi2'] == null){ 
    echo "No Data to add"; 
} else { 
     $doi2 = $_POST['doi2']; 
     $title2 = $_POST['title2']; 
     $year2 = $_POST['year2']; 
     $journal2 = $_POST['journal2']; 

     $sql="INSERT INTO ref(uid, date, doi, title, year, journal) VALUES('1', 'CURDATE()', '$doi2', '$title2', '$year2', '$journal2')"; 
     if (!mysqli_query($link, $sql, $con)) 
     { 
      die('The Reference could not be added, beacuse of SQL Error:' . mysql_error()); 
     } 
     echo "New Reference Added"; 
} 
?> 
+0

무엇이 바뀌 었습니까? –

+0

큰 따옴표가 있습니다. $ _POST를 쿼리에서 변경하고 쿼리 전에 정의한 변수를 제공했습니다. –

+0

또한 null과 비교할 때 따옴표가 필요하지 않습니다. –