简体   繁体   English

无法使用 php 'ERROR!' 在 mysql 数据库中插入数据

[英]Unable to insert data in mysql database with php 'ERROR!'

I don't know where I'm doing wrong.我不知道我哪里做错了。 The task is not completing.任务没有完成。 I have huge content and wanna insert the data in database.我有大量的内容,想在数据库中插入数据。

    <?php
    $servername = "localhost";
    $username = "xxx";
    $password = "xxxx";
    $db_name = "xxxxxx";

    // Create connection
    $conn = new mysqli($servername, $username, $password, $db_name);

    // Check connection
    if ($conn->connect_error){
      die("Connection failed: " . $conn->connect_error);
    } 
    $conn->set_charset('utf8');
    $sql = "INSERT INTO lyrics_a (title, content, category) VALUES 
(
[
'xxxxx',
'xxxxxxx<br>xxxxxxxxx<br>xxxxxx',
'xxxxxxxxx'
]
[
'xxxxx',
'xxxxxxx<br>xxxxxxxxx<br>xxxxxx',
'xxxxxxxxx'
]
[
'xxxxx',
'xxxxxxx<br>xxxxxxxxx<br>xxxxxx',
'xxxxxxxxx'
]
)";

    if ($conn->query($sql) === TRUE) {
        echo "New record created successfully";
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }

    $conn->close();
    ?> 

Error message :错误信息 :

Error: INSERT INTO lyrics_a ('title', 'content', 'category') VALUES ([' xxx','xxx','xxxx' ])
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''title', 'content', 'category') VALUES ([' xxx,'xxx','xxxx' ])' at line 1 

I'm newbie.我是新手。 Please help.请帮忙。 Thank you.谢谢你。

You're missing a single quote.你缺少一个单引号。

INSERT INTO lyrics_a ('title', 'content', 'category') VALUES (['xxx->HERE<-,'xxx','xxxx' ])

You cannot insert 3 values at the same time, try to do it separately.您不能同时插入 3 个值,请尝试分别进行。
You may also want to use preg-quote on your values.您可能还想对您的值使用preg-quote

A missing ' in your Values and a unneeded ' in the column name 'content您的值中缺少'并且列名'content不需要'

Instead of this:取而代之的是:

$sql = "INSERT INTO lyrics_a (title, 'content, category) VALUES 
(
[
'xxxxx',
'xxxxxxx<br>xxxxxxxxx<br>xxxxxx',
'xxxxxxxxx'
]
[
'xxxxx',
'xxxxxxx<br>xxxxxxxxx<br>xxxxxx',
'xxxxxxxxx'
]
[
'xxxxx',
'xxxxxxx<br>xxxxxxxxx<br>xxxxxx',
'xxxxxxxxx'
]
)";

Try this:尝试这个:

$sql = "INSERT INTO lyrics_a (title, content, category) VALUES ('xx','xxx','xxxx')";

Note: If xx , xxx , xxxx are strings, use proper wrapping like in the example below.注意:如果xxxxxxxxx是字符串,请使用正确的包装,如下例所示。

$xx = "";
$xxx = "";
$xxxx = "";
$sql = "INSERT INTO lyrics_a (title, content, category) VALUES ('$xx','$xxx','$xxxx')";

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

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