0

我不断得到一个

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";
    }
?>
4

2 回答 2

2

这一行,key需要有引号,

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

此外,如果你想检查empty条目,你可能需要这样做,

if ($_POST['doi2'] == ""){ //checking "NULL", checks for a string 'NULL'
于 2012-10-23T16:01:33.113 回答
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";
}
?>
于 2012-10-23T16:06:15.080 回答