简体   繁体   English

解析错误:语法错误,第6行意外T_STRING

[英]Parse error: syntax error, unexpected T_STRING on line 6

I keep getting a 我一直在接受

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

I have read loads of different solutions to this problem but non seem to work 我已经阅读了大量不同的解决方案来解决这个问题,但似乎没有用

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

This line, the key needs to have quotes, 这一行,关键需要有引号,

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

Also, if you want to check for empty entries, you need to probably do this, 此外,如果要检查empty条目,您可能需要这样做,

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

Rewrite the code in the below way. 以下面的方式重写代码。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM